Skip to content

Commit

Permalink
Fix retrieveSigningKeys error (#242)
Browse files Browse the repository at this point in the history
* Update utils.js

* Update .eslintrc and fix linting errors
  • Loading branch information
davidpatrick authored Apr 9, 2021
1 parent 3333e6c commit fd3a2c7
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
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

0 comments on commit fd3a2c7

Please sign in to comment.