Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/oauth4webapi/mod.ts>experimental_jwksCache

OAuth 2 / OpenID Connect for JavaScript Runtimes
Latest
variable experimental_jwksCache
import { experimental_jwksCache } from "https://deno.land/x/oauth4webapi@v2.11.1/mod.ts";

This is an experimental feature, it is not subject to semantic versioning rules. Non-backward compatible changes or removal may occur in any future release.

DANGER ZONE - This option has security implications that must be understood, assessed for applicability, and accepted before use. It is critical that the JSON Web Key Set cache only be writable by your own code.

This option is intended for cloud computing runtimes that cannot keep an in memory cache between their code's invocations. Use in runtimes where an in memory cache between requests is available is not desirable.

When configured on an interface that extends JWKSCacheOptions, this applies to options parameter for functions that trigger HTTP requests for the AuthorizationServer.jwks_uri | as.jwks_uri, this allows the passed in object to:

  • Serve as an initial value for the JSON Web Key Set that the module would otherwise need to trigger an HTTP request for
  • Have the JSON Web Key Set the function optionally ended up triggering an HTTP request for assigned to it as properties

The intended use pattern is:

  • Before executing a function with JWKSCacheOptions in its options parameter you pull the previously cached object from a low-latency key-value store offered by the cloud computing runtime it is executed on;
  • Default to an empty object {} instead when there's no previously cached value;
  • Pass it into the options interfaces that extend JWKSCacheOptions;
  • Afterwards, update the key-value storage if the ExportedJWKSCache.uat | uat property of the object has changed.

Examples

Example 1

import * as oauth from 'oauth4webapi'

// Prerequisites
let as!: oauth.AuthorizationServer
let request!: Request
let expectedAudience!: string

// Load JSON Web Key Set cache
const jwksCache: oauth.JWKSCacheInput = (await getPreviouslyCachedJWKS()) || {}
const { uat } = jwksCache

// Use JSON Web Key Set cache
const accessTokenClaims = await validateJwtAccessToken(as, request, expectedAudience, {
  [oauth.experimental_jwksCache]: jwksCache,
})

if (uat !== jwksCache.uat) {
  // Update JSON Web Key Set cache
  await storeNewJWKScache(jwksCache)
}

type

unique symbol