docs/jwks/remote/variables/jwksCache.md
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.
⢠const jwksCache: unique symbol
Symbol used to configure an externally persisted remote JWKS cache.
[!WARNING]
Only trusted application code must be allowed to write this cache; its keys are trusted for signature verification.
This option is intended for cloud computing runtimes that cannot keep an in memory cache between
their code's invocations. The supplied writable object seeds the resolver's cache and is updated
with jwks and uat after a successful fetch; persist it whenever uat changes. Using this in
runtimes that can keep an in-memory cache between requests is not desirable.
When passed to createRemoteJWKSet this allows the passed in object to:
The intended use pattern is:
{} instead when there's no previously cached value;uat property of
the object has changed.// Prerequisites
let url!: URL
let jwt!: string
let getPreviouslyCachedJWKS!: () => Promise<jose.ExportedJWKSCache>
let storeNewJWKScache!: (cache: jose.ExportedJWKSCache) => Promise<void>
// Load JSON Web Key Set cache
const jwksCache: jose.JWKSCacheInput = (await getPreviouslyCachedJWKS()) || {}
const { uat } = jwksCache
const JWKS = jose.createRemoteJWKSet(url, {
[jose.jwksCache]: jwksCache,
})
// Use JSON Web Key Set cache
await jose.jwtVerify(jwt, JWKS)
if (uat !== jwksCache.uat) {
// Update JSON Web Key Set cache
await storeNewJWKScache(jwksCache)
}