diff --git a/.eslintrc b/.eslintrc index 2751224..f3f6d13 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,6 +21,9 @@ "space-before-blocks": [2, "always"] }, "env": { - "node": true - } + "node": true, + "mocha": true, + "es6": true + }, + "extends": "eslint:recommended" } diff --git a/src/integrations/express.js b/src/integrations/express.js index e611f22..affa5c4 100644 --- a/src/integrations/express.js +++ b/src/integrations/express.js @@ -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); } diff --git a/src/integrations/hapi.js b/src/integrations/hapi.js index 51ca8ff..cf53972 100644 --- a/src/integrations/hapi.js +++ b/src/integrations/hapi.js @@ -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). diff --git a/src/integrations/passport.js b/src/integrations/passport.js index 6fed323..a3981e1 100644 --- a/src/integrations/passport.js +++ b/src/integrations/passport.js @@ -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); diff --git a/src/utils.js b/src/utils.js index a8ff44a..6b06404 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,4 @@ const jose = require('jose'); -const JwksError = require('./errors/JwksError'); function retrieveSigningKeys(keys) { const keystore = jose.JWKS.asKeyStore({ keys }, { ignoreErrors: true }); diff --git a/src/wrappers/cache.js b/src/wrappers/cache.js index 6bd0307..5a1ace9 100644 --- a/src/wrappers/cache.js +++ b/src/wrappers/cache.js @@ -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({ diff --git a/src/wrappers/interceptor.js b/src/wrappers/interceptor.js index 601c58e..5f0eb1d 100644 --- a/src/wrappers/interceptor.js +++ b/src/wrappers/interceptor.js @@ -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) => { diff --git a/src/wrappers/rateLimit.js b/src/wrappers/rateLimit.js index 1dd2ef4..ebdf4cc 100644 --- a/src/wrappers/rateLimit.js +++ b/src/wrappers/rateLimit.js @@ -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);