diff --git a/lib.js b/lib.js index 37b7d3d..c1d2aa1 100644 --- a/lib.js +++ b/lib.js @@ -40,6 +40,13 @@ const jwtOptions = { issuer: process.env.TOKEN_ISSUER }; +const client = jwksClient({ + cache: true, + rateLimit: true, + jwksRequestsPerMinute: 10, // Default value + jwksUri: process.env.JWKS_URI +}); + module.exports.authenticate = (params) => { console.log(params); const token = getToken(params); @@ -49,13 +56,6 @@ module.exports.authenticate = (params) => { throw new Error('invalid token'); } - const client = jwksClient({ - cache: true, - rateLimit: true, - jwksRequestsPerMinute: 10, // Default value - jwksUri: process.env.JWKS_URI - }); - const getSigningKey = util.promisify(client.getSigningKey); return getSigningKey(decoded.header.kid) .then((key) => {