@connectedcars/jwtutils
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -48,3 +48,3 @@ 'use strict' | ||
}) | ||
jwtEncode.stderr.on('data', () => { | ||
jwtEncode.stderr.on('end', () => { | ||
stderrStr = Buffer.concat(errorData).toString('utf8') | ||
@@ -51,0 +51,0 @@ }) |
{ | ||
"name": "@connectedcars/jwtutils", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Zero dependency JWT encoding/decoding for Node", | ||
@@ -28,2 +28,4 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"@types/mocha": "^2.2.45", | ||
"@types/node": "^8.5.2", | ||
"babel-eslint": "^7.2.3", | ||
@@ -30,0 +32,0 @@ "benchmark": "^2.1.4", |
@@ -135,3 +135,3 @@ # node-jwtutils | ||
// Register the middleware | ||
app.use(JwtAuthMiddleware(pubKeys, audiences, user => { | ||
app.use(JwtAuthMiddleware(pubKeys, audiences, user => { // Also supports Promises and async | ||
if (user.issuer === 'https://jwt.io/') { | ||
@@ -138,0 +138,0 @@ if (!user.subject.match(/^[^@]+@domain\.tld$/)) { |
@@ -0,1 +1,4 @@ | ||
// @ts-check | ||
'use strict' | ||
function base64EncodeUrlSafe(buffer) { | ||
@@ -2,0 +5,0 @@ return buffer |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -356,3 +357,3 @@ | ||
let customJwtHeader = Object.assign({}, jwtHeader) | ||
customJwtHeader.kid = 2 | ||
customJwtHeader.kid = '2' | ||
let jwt = JwtUtils.encode(rsaPrivateKey, customJwtHeader, jwtBody) | ||
@@ -359,0 +360,0 @@ try { |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -20,2 +21,3 @@ | ||
} | ||
request.user = { | ||
@@ -28,7 +30,13 @@ audience: decodedJwtBody.aud, | ||
} | ||
// Handle async | ||
let result | ||
if (typeof mapper === 'function') { | ||
mapper(request.user) | ||
result = mapper(request.user, request, response) | ||
} | ||
return next() | ||
if (isPromise(result)) { | ||
result.then(() => next()).catch(e => next(e)) | ||
} else { | ||
return next() | ||
} | ||
} catch (e) { | ||
@@ -44,2 +52,10 @@ if (e instanceof JwtVerifyError) { | ||
function isPromise(value) { | ||
return ( | ||
typeof value === 'object' && | ||
value !== null && | ||
typeof value.then === 'function' | ||
) | ||
} | ||
module.exports = jwtAuthMiddleware |
@@ -0,1 +1,4 @@ | ||
// @ts-check | ||
'use strict' | ||
const express = require('express') | ||
@@ -68,2 +71,12 @@ const app = express() | ||
) | ||
app.use( | ||
'/async', | ||
JwtAuthMiddleware(pubKeys, audiences, user => { | ||
if (user.subject === 'error') { | ||
return Promise.reject(new JwtVerifyError('Async error')) | ||
} else { | ||
return Promise.resolve('test') | ||
} | ||
}) | ||
) | ||
app.use('/', JwtAuthMiddleware(pubKeys, audiences)) | ||
@@ -83,2 +96,5 @@ app.use((err, req, res, next) => { | ||
}) | ||
app.get('/async', function(req, res) { | ||
res.send(`Async response`) | ||
}) | ||
@@ -164,2 +180,29 @@ done() | ||
}) | ||
it('should fail with async error', () => { | ||
let customJwtBody = Object.assign({}, jwtBody) | ||
customJwtBody.sub = 'error' | ||
let jwt = JwtUtils.encode(ecPrivateKey, jwtHeader, customJwtBody) | ||
let responsePromise = doRequest('GET', 'localhost', port, '/async', { | ||
Authorization: 'Bearer ' + jwt, | ||
Accept: 'application/json', | ||
'User-Agent': 'test', | ||
'X-Error': 'Async error' | ||
}) | ||
return expect(responsePromise, 'to be fulfilled with value satisfying', { | ||
statusCode: 401, | ||
data: 'Async error' | ||
}) | ||
}) | ||
it('should success with async', () => { | ||
let jwt = JwtUtils.encode(ecPrivateKey, jwtHeader, jwtBody) | ||
let responsePromise = doRequest('GET', 'localhost', port, '/async', { | ||
Authorization: 'Bearer ' + jwt, | ||
Accept: 'application/json', | ||
'User-Agent': 'test' | ||
}) | ||
return expect(responsePromise, 'to be fulfilled with value satisfying', { | ||
statusCode: 200, | ||
data: 'Async response' | ||
}) | ||
}) | ||
}) | ||
@@ -166,0 +209,0 @@ }) |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
'use strict' | ||
@@ -2,0 +3,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 7 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 10 instances in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5959492
870
85996
14
2
90
5
88
47