Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retrieveSigningKeys error #242

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"space-before-blocks": [2, "always"]
},
"env": {
"node": true
}
"node": true,
"mocha": true,
"es6": true
},
"extends": "eslint:recommended"
}
4 changes: 2 additions & 2 deletions src/integrations/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ module.exports.expressJwtSecret = function (options) {
}

const client = new JwksClient(options);
const onError = options.handleSigningKeyError || handleSigningKeyError;
const onError = options.handleSigningKeyError || handleSigningKeyError;

return function secretProvider(req, header, payload, cb) {
if (!header || !supportedAlg.includes(header.alg)) {
if (!header || !supportedAlg.includes(header.alg)) {
return cb(null, null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/integrations/hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports.hapiJwt2Key = function (options) {
}

const client = new JwksClient(options);
const onError = options.handleSigningKeyError || handleSigningKeyError;
const onError = options.handleSigningKeyError || handleSigningKeyError;

return function secretProvider(decoded, cb) {
// We cannot find a signing certificate if there is no header (no kid).
Expand Down
6 changes: 4 additions & 2 deletions src/integrations/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ module.exports.passportJwtSecret = function (options) {
}

const client = new JwksClient(options);
const onError = options.handleSigningKeyError || handleSigningKeyError;
const onError = options.handleSigningKeyError || handleSigningKeyError;

return function secretProvider(req, rawJwtToken, cb) {
let decoded;
try {
decoded = JWT.decode(rawJwtToken, { complete: true });
} catch (err) {}
} catch (err) {
decoded = null;
}

if (!decoded || !supportedAlg.includes(decoded.header.alg)) {
return cb(null, null);
Expand Down
9 changes: 2 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const jose = require('jose');
const JwksError = require('./errors/JwksError');

function retrieveSigningKeys(keys) {
let keystore = [];
try {
keystore = jose.JWKS.asKeyStore({ keys }, { ignoreErrors: true });
} catch (err) {
return cb(new JwksError(err.message));
}
const keystore = jose.JWKS.asKeyStore({ keys }, { ignoreErrors: true });

return keystore.all({ use: 'sig' }).map((key) => {
return {
kid: key.kid,
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/cache.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const debug = require('debug');
const memoizer = require('lru-memoizer');

function cacheWrapper(client, { cacheMaxEntries = 5, cacheMaxAge = 600000 } = options) {
function cacheWrapper(client, { cacheMaxEntries = 5, cacheMaxAge = 600000 }) {
const logger = debug('jwks');
logger(`Configured caching of signing keys. Max: ${cacheMaxEntries} / Age: ${cacheMaxAge}`);
return memoizer.sync({
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const retrieveSigningKeys = require('../utils').retrieveSigningKeys;
* Uses getKeysInterceptor to allow users to retrieve keys from a file,
* external cache, or provided object before falling back to the jwksUri endpoint
*/
function getKeysInterceptor(client, { getKeysInterceptor } = options) {
function getKeysInterceptor(client, { getKeysInterceptor }) {
const getSigningKey = client.getSigningKey.bind(client);

return async (kid) => {
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/rateLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { RateLimiter } = require('limiter');

const JwksRateLimitError = require('../errors/JwksRateLimitError');

function rateLimtWrapper(client, { jwksRequestsPerMinute = 10 } = options) {
function rateLimtWrapper(client, { jwksRequestsPerMinute = 10 }) {
const logger = debug('jwks');
const getSigningKey = client.getSigningKey.bind(client);

Expand Down