in src/jwk.ts [61:79]
export async function fetchJwk(
jwksUri: string,
decomposedJwt: DecomposedJwt
): Promise<Jwk> {
if (!decomposedJwt.header.kid) {
throw new JwtWithoutValidKidError(
"JWT header does not have valid kid claim"
);
}
const jwk = (await fetchJwks(jwksUri)).keys.find(
(key) => key.kid === decomposedJwt.header.kid
);
if (!jwk) {
throw new KidNotFoundInJwksError(
`JWK for kid "${decomposedJwt.header.kid}" not found in the JWKS`
);
}
return jwk;
}