Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jwks/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class LocalJWKSet {
const { 0: jwk, length } = candidates

if (length === 0) {
throw new JWKSNoMatchingKey()
throw new JWKSNoMatchingKey(kid)
}
if (length !== 1) {
const error = new JWKSMultipleMatchingKeys()
Expand Down
6 changes: 3 additions & 3 deletions src/util/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ export class JWKSNoMatchingKey extends JOSEError {

/** @ignore */
constructor(
message = 'no applicable key found in the JSON Web Key Set',
options?: { cause?: unknown },
kid?: string
) {
super(message, options)
const postfix = typeof kid === 'string' && kid.length > 0 ? ` for kid: ${kid}` : '';
super(`no applicable key found in the JSON Web Key Set${postfix}`)
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/jwks/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ test.serial('RemoteJWKSet', async (t) => {
const jwt = await new SignJWT().setProtectedHeader({ alg: 'PS256', kid: jwk.kid }).sign(key)
await t.throwsAsync(jwtVerify(jwt, JWKS), {
code: 'ERR_JWKS_NO_MATCHING_KEY',
message: 'no applicable key found in the JSON Web Key Set',
message: 'no applicable key found in the JSON Web Key Set for kid: ' + jwk.kid,
})
}
{
Expand Down Expand Up @@ -230,7 +230,7 @@ test.serial('refreshes the JWKS once off cooldown', async (t) => {
const jwt = await new SignJWT().setProtectedHeader({ alg: 'ES256', kid: 'two' }).sign(key)
await t.throwsAsync(jwtVerify(jwt, JWKS), {
code: 'ERR_JWKS_NO_MATCHING_KEY',
message: 'no applicable key found in the JSON Web Key Set',
message: 'no applicable key found in the JSON Web Key Set for kid: two',
})
jwks.keys[0].kid = 'two'
mockAgent.intercept({ path: '/jwks' }).reply(200, jwks)
Expand Down Expand Up @@ -275,7 +275,7 @@ test.serial('createRemoteJWKSet manual reload', async (t) => {
const jwt = await new SignJWT().setProtectedHeader({ alg: 'ES256', kid: 'two' }).sign(key)
await t.throwsAsync(jwtVerify(jwt, JWKS), {
code: 'ERR_JWKS_NO_MATCHING_KEY',
message: 'no applicable key found in the JSON Web Key Set',
message: 'no applicable key found in the JSON Web Key Set for kid: two',
})
jwks.keys[0].kid = 'two'
mockAgent.intercept({ path: '/jwks' }).reply(200, jwks)
Expand Down