fix(identity-webhook): resolve JWKS via OIDC discovery#62
Conversation
|
Next in stack: #63 (composite app token exchange), based on this branch. |
There was a problem hiding this comment.
Pull request overview
This PR updates the identity-webhook OIDC verifier to resolve JWKS via issuer-relative OIDC Discovery (/.well-known/openid-configuration → jwks_uri) instead of assuming {issuer}/.well-known/jwks.json, and adds tests for both discovery and legacy env overrides.
Changes:
- Add
discoverJwksUri()and updatecreateOidcVerifier()to resolve JWKS via OIDC Discovery with explicitjwks/jwksUritaking precedence. - Add/extend unit tests covering discovery behavior and end-to-end verification using discovery.
- Add
resolveLegacyJwksUri()to preserveOIDC_JWKS_URI/JWKS_URIoverride behavior for legacy env configuration.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| identity-webhook/verifiers.mjs | Implements OIDC discovery-based JWKS URI resolution and integrates it into OIDC verification. |
| identity-webhook/verifiers.test.mjs | Adds unit tests for discovery and verification-through-discovery behavior. |
| identity-webhook/verifiers.d.ts | Updates public types to include discoverJwksUri and correct jwks typing. |
| identity-webhook/legacy-env.mjs | Adds resolveLegacyJwksUri and wires it into legacy OIDC verifier creation. |
| identity-webhook/legacy-env.test.mjs | Adds unit tests for legacy JWKS URI override resolution. |
| identity-webhook/legacy-env.d.ts | Exposes resolveLegacyJwksUri in type declarations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace the incorrect default {issuer}/.well-known/jwks.json with
issuer-relative OIDC discovery (openid-configuration → jwks_uri).
Validate discovery issuer, wrap JWKS fetch errors with the URL, and
keep OIDC_JWKS_URI as an explicit override. Unit tests cover discovery
and leave api_key mode unchanged.
70f732d to
301770e
Compare
|
Retargeted to
|
Accept Bearer app_<clientId>.pmth_<key> when OIDC_TOKEN_EXCHANGE_BASE_URL is set: RFC 8693 exchange at the app-scoped token endpoint, then jwtVerify the minted access token (same JWKS discovery path as #62). Harden cache keys (salted HKDF) and log sanitization. Document exchange env vars.
Accept Bearer app_<24hex>_<secret> when OIDC_TOKEN_EXCHANGE_BASE_URL is set: RFC 8693 exchange at the app-scoped token endpoint, then jwtVerify the minted access token (same JWKS discovery path as #62). Secret segment is opaque (operator prefixes allowed); reject cs_ / _cs_ client-secret shapes. Harden cache keys (salted HKDF) and log sanitization. Document exchange env vars.
Clear the in-flight discovery promise on failure so later verifies can retry, and wrap createLocalJWKSet errors with the JWKS URL.
Move the OIDC discovery docs off normalizeIssuer and align the non-ok HTTP error message with response.ok (2xx).
Trim issuers, reject blank jwtIssuer, require jwks to be a jose key function, and align JWKS non-ok HTTP errors with response.ok.
Wrap createRemoteJWKSet URL construction so Invalid URL failures retain the offending jwks_uri / OIDC_JWKS_URI in the verify warn log.
|
@rickstaa This PR is ready for review, it is a simple bug fix to ensure OIDC issuer resolution follows conventional |
Replace hardcoded issuer URLs in the documentation and unit tests with a more generic example. This change improves clarity and consistency in the OIDC discovery process.
| /** Trim and strip a trailing slash so issuer comparisons are stable. */ | ||
| function normalizeIssuer(issuer) { | ||
| return String(issuer ?? "").trim().replace(/\/$/, ""); | ||
| } |
Summary
/.well-known/openid-configuration→jwks_uri) instead of the incorrect{issuer}/.well-known/jwks.jsondefault.OIDC_JWKS_URIoverride; validate discoveryissueragainstjwtIssuer; wrap JWKS fetch/parse errors with the URL.api_keymode tests remain green (built-in webhook path unchanged).Why
Issuers that are not at the IdP root (e.g.
…/api/v1/oidc) advertise JWKS at a path like…/api/v1/oidc/jwks, not…/api/v1/oidc/.well-known/jwks.json. This matches builder-sdk / oauth4webapi behavior.Test plan
cd identity-webhook && npm testNotes
main(no npm publish workflow in this PR).