Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for caching in JwtUtils.decode #12

Open
tlbdk opened this issue Feb 13, 2018 · 0 comments
Open

Add support for caching in JwtUtils.decode #12

tlbdk opened this issue Feb 13, 2018 · 0 comments

Comments

@tlbdk
Copy link
Member

tlbdk commented Feb 13, 2018

Add examples with:

class TokenCache {
   constructor(pubKeys) {
      this.pubkeys = {}
      this.tokens = {}
   }
   set(jwt, jwtHeader, jwtBody) {
      this.tokens[jwt] = {
        body: jwtBody,
        expiresAt: Math.max(jwtBody.expiresAt, Date.now() + 3600 * 1000) // Don't cache for more than an hour
     }
   }
   get(jwt) {
     // Check expiresAt
     return this.tokens[jwt].body
   }
}

let tokenCache = new TokenCache()
let decodedJwtBody = JwtUtils.decode(jwt, pubKeys, allowedAudinces, { cache: tokenCache })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant