diff --git a/.changeset/late-cooks-collect.md b/.changeset/late-cooks-collect.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/late-cooks-collect.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/backend/src/constants.ts b/packages/backend/src/constants.ts index da79802049..ce7a8d7c5c 100644 --- a/packages/backend/src/constants.ts +++ b/packages/backend/src/constants.ts @@ -4,6 +4,7 @@ export const API_VERSION = 'v1'; // TODO: Get information from package.json or define them from ESBuild export const USER_AGENT = `@clerk/backend`; export const MAX_CACHE_LAST_UPDATED_AT_SECONDS = 5 * 60; +export const JWKS_CACHE_TTL_MS = 1000 * 60 * 60; const Attributes = { AuthStatus: '__clerkAuthStatus', diff --git a/packages/backend/src/tokens/keys.ts b/packages/backend/src/tokens/keys.ts index a2f4ebb4a2..175c956271 100644 --- a/packages/backend/src/tokens/keys.ts +++ b/packages/backend/src/tokens/keys.ts @@ -1,4 +1,4 @@ -import { API_URL, API_VERSION, MAX_CACHE_LAST_UPDATED_AT_SECONDS } from '../constants'; +import { API_URL, API_VERSION, JWKS_CACHE_TTL_MS, MAX_CACHE_LAST_UPDATED_AT_SECONDS } from '../constants'; // DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js // For more information refer to https://sinonjs.org/how-to/stub-dependency/ import runtime from '../runtime'; @@ -27,10 +27,7 @@ function getCacheValues() { return Object.values(cache); } -function setInCache( - jwk: JsonWebKeyWithKid, - jwksCacheTtlInMs: number = 1000 * 60 * 60, // 1 hour -) { +function setInCache(jwk: JsonWebKeyWithKid, jwksCacheTtlInMs: number) { cache[jwk.kid] = jwk; lastUpdatedAt = Date.now(); @@ -128,7 +125,7 @@ export async function loadClerkJWKFromRemote({ apiVersion = API_VERSION, issuer, kid, - jwksCacheTtlInMs = 1000 * 60 * 60, // 1 hour, + jwksCacheTtlInMs = JWKS_CACHE_TTL_MS, skipJwksCache, }: LoadClerkJWKFromRemoteOptions): Promise { const shouldRefreshCache = !getFromCache(kid) && reachedMaxCacheUpdatedAt();