Skip to content

Commit

Permalink
Fixing RS256/Machine-Token verification signing key caching issue. Ea…
Browse files Browse the repository at this point in the history
…rlier it was not caching.
  • Loading branch information
Sachin Maheshwari committed Jun 12, 2019
1 parent 0d8b4df commit 4e7f80c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/auth/verifier.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'
var jwt = require('jsonwebtoken'),
const jwt = require('jsonwebtoken'),
jwksRSA = require('jwks-rsa'),
ms = require('millisecond')

const jwksClients = {} // in global scope

module.exports = function(validIssuers, jwtKeyCacheTime) {

return {
Expand All @@ -15,9 +17,6 @@ module.exports = function(validIssuers, jwtKeyCacheTime) {
* @param callback callback to pass responses
*/
validateToken: (token, secret, callback) => {

let jwksClients = {}

// Decode it first
let decodedToken = jwt.decode(token, {complete: true})

Expand All @@ -35,7 +34,7 @@ module.exports = function(validIssuers, jwtKeyCacheTime) {
jwksClients[decodedToken.payload.iss] = jwksRSA({
cache: true,
cacheMaxEntries: 5, // Default value
cacheMaxAge: ms(jwtKeyCacheTime), // Default value
cacheMaxAge: ms(jwtKeyCacheTime), // undefined/0 means infinte
jwksUri: decodedToken.payload.iss + '.well-known/jwks.json'
})
}
Expand Down

0 comments on commit 4e7f80c

Please sign in to comment.