Skip to content

Commit

Permalink
Merge pull request #19 from appirio-tech/dev
Browse files Browse the repository at this point in the history
Fixing RS256/Machine-Token verification signing key caching issue.
  • Loading branch information
sachin-maheshwari authored Jun 13, 2019
2 parents 51e7230 + 4e7f80c commit f453529
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 f453529

Please sign in to comment.