diff --git a/src/jwks/local.ts b/src/jwks/local.ts index aa65e1ec09..474eb2c1d8 100644 --- a/src/jwks/local.ts +++ b/src/jwks/local.ts @@ -32,8 +32,7 @@ interface Cache { [alg: string]: KeyLikeType } -/** @private */ -export function isJWKSLike(jwks: unknown): jwks is JSONWebKeySet { +function isJWKSLike(jwks: unknown): jwks is JSONWebKeySet { return ( jwks && typeof jwks === 'object' && diff --git a/src/jwks/remote.ts b/src/jwks/remote.ts index cbcfdbd6e2..3e0f861a18 100644 --- a/src/jwks/remote.ts +++ b/src/jwks/remote.ts @@ -1,9 +1,9 @@ import fetchJwks from '../runtime/fetch_jwks.js' -import type { KeyLike, JWSHeaderParameters, FlattenedJWSInput } from '../types.d' -import { JWKSInvalid, JWKSNoMatchingKey } from '../util/errors.js' +import type { KeyLike, JWSHeaderParameters, FlattenedJWSInput, JSONWebKeySet } from '../types.d' +import { JWKSNoMatchingKey } from '../util/errors.js' -import { isJWKSLike, LocalJWKSet } from './local.js' +import { createLocalJWKSet } from './local.js' function isCloudflareWorkers() { return ( @@ -65,7 +65,7 @@ export interface RemoteJWKSetOptions { headers?: Record } -class RemoteJWKSet extends LocalJWKSet { +class RemoteJWKSet { private _url: URL private _timeoutDuration: number @@ -80,11 +80,9 @@ class RemoteJWKSet extends LocalJWKSet - constructor(url: unknown, options?: RemoteJWKSetOptions) { - super({ keys: [] }) - - this._jwks = undefined + private _local!: ReturnType> + constructor(url: unknown, options?: RemoteJWKSetOptions) { if (!(url instanceof URL)) { throw new TypeError('url must be an instance of URL') } @@ -113,17 +111,17 @@ class RemoteJWKSet extends LocalJWKSet { - if (!this._jwks || !this.fresh()) { + if (!this._local || !this.fresh()) { await this.reload() } try { - return await super.getKey(protectedHeader, token) + return await this._local(protectedHeader, token) } catch (err) { if (err instanceof JWKSNoMatchingKey) { if (this.coolingDown() === false) { await this.reload() - return super.getKey(protectedHeader, token) + return this._local(protectedHeader, token) } } throw err @@ -145,11 +143,7 @@ class RemoteJWKSet extends LocalJWKSet { - if (!isJWKSLike(json)) { - throw new JWKSInvalid('JSON Web Key Set malformed') - } - - this._jwks = { keys: json.keys } + this._local = createLocalJWKSet((json)) this._jwksTimestamp = Date.now() this._pendingFetch = undefined })