Comparing version 2.2.3 to 3.0.0
{ | ||
"name": "fast-jwt", | ||
"version": "2.2.3", | ||
"version": "3.0.0", | ||
"description": "Fast JSON Web Token implementation", | ||
@@ -5,0 +5,0 @@ "author": "NearForm Ltd", |
@@ -65,5 +65,11 @@ import 'node' | ||
type DecodedJwt = { | ||
header: { [key: string]: any }, | ||
payload: string, | ||
signature: string | ||
} | ||
type KeyFetcher = | ||
| ((header: { [key: string]: any }) => Promise<string | Buffer>) | ||
| ((header: { [key: string]: any }, cb: (err: Error | TokenError | null, key: string | Buffer) => void) => void) | ||
| ((DecodedJwt: DecodedJwt) => Promise<string | Buffer>) | ||
| ((DecodedJwt: DecodedJwt, cb: (err: Error | TokenError | null, key: string | Buffer) => void) => void) | ||
@@ -70,0 +76,0 @@ declare function SignerSync(payload: string | Buffer | { [key: string]: any }): string |
@@ -18,6 +18,6 @@ 'use strict' | ||
const supportedAlgorithms = Array.from( | ||
new Set([...hsAlgorithms, ...esAlgorithms, ...rsaAlgorithms, ...edAlgorithms, 'none']) | ||
).join(', ') | ||
const supportedAlgorithms = new Set([...hsAlgorithms, ...esAlgorithms, ...rsaAlgorithms, ...edAlgorithms, 'none']) | ||
const supportedAlgorithmsList = Array.from(supportedAlgorithms).join(', ') | ||
function checkIsCompatibleAlgorithm(expected, actual) { | ||
@@ -129,3 +129,3 @@ const expectedType = expected.slice(0, 2) | ||
// Get the key asynchronously | ||
getAsyncKey(key, header, (err, currentKey) => { | ||
getAsyncKey(key, { header, payload }, (err, currentKey) => { | ||
if (err) { | ||
@@ -198,11 +198,7 @@ const error = TokenError.wrap(err, TokenError.codes.keyFetchingError, 'Cannot fetch key.') | ||
algorithm && | ||
algorithm !== 'none' && | ||
!hsAlgorithms.includes(algorithm) && | ||
!esAlgorithms.includes(algorithm) && | ||
!rsaAlgorithms.includes(algorithm) && | ||
!edAlgorithms.includes(algorithm) | ||
!supportedAlgorithms.has(algorithm) | ||
) { | ||
throw new TokenError( | ||
TokenError.codes.invalidOption, | ||
`The algorithm option must be one of the following values: ${supportedAlgorithms}.` | ||
`The algorithm option must be one of the following values: ${supportedAlgorithmsList}.` | ||
) | ||
@@ -291,4 +287,7 @@ } | ||
const fpo = { jti, aud, iss, sub, nonce } | ||
const fixedPayload = Object.keys(fpo).reduce((obj, key) => { | ||
return fpo[key] !== undefined ? Object.assign(obj, { [key]: fpo[key] }) : obj | ||
const fixedPayload = Object.entries(fpo).reduce((obj, [key, value]) => { | ||
if (value !== undefined) { | ||
obj[key] = value | ||
} | ||
return obj | ||
}, {}) | ||
@@ -295,0 +294,0 @@ |
@@ -8,4 +8,4 @@ 'use strict' | ||
function getAsyncKey(handler, header, callback) { | ||
const result = handler(header, callback) | ||
function getAsyncKey(handler, decoded, callback) { | ||
const result = handler(decoded, callback) | ||
@@ -35,3 +35,3 @@ if (result && typeof result.then === 'function') { | ||
return [ | ||
function(err, token) { | ||
function (err, token) { | ||
if (err) { | ||
@@ -38,0 +38,0 @@ return promiseReject(err) |
@@ -327,3 +327,3 @@ 'use strict' | ||
// Get the key asynchronously | ||
getAsyncKey(key, header, (err, currentKey) => { | ||
getAsyncKey(key, { header, payload, signature }, (err, currentKey) => { | ||
if (err) { | ||
@@ -330,0 +330,0 @@ return callback( |
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
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
89483
1294