On this page
An OIDC JWKS endpoint not reachable error can turn an otherwise routine API release into a token-verification outage. The cause may be a network failure, an outdated discovery document, or a key cache that has not caught up with rotation.
This guide shows how to inspect discovery metadata and test the published JWKS endpoint from a non-production environment. Reachability is only the first check: a successful response does not prove that its keys are appropriate for your tokens or that verification is secure.
Key Takeaways
- Start with the discovery document for your configured, trusted issuer; find its
jwks_uriand check that the metadata'sissuermatches your configuration. - Test the JWKS URL from the API's actual network environment, not just a developer laptop.
- Check HTTP status and JSON structure, then separately test key selection and token verification using non-production credentials.
- Plan for discovery and key rotation: stale metadata and cached keys can cause failures even when an endpoint is reachable.
- A JWKS published for verification must not expose private key material. Do not paste real tokens or keys into tickets or diagnostic tools.
What discovery and JWKS do
An OpenID Connect provider publishes discovery metadata describing the issuer and its endpoints. The metadata's jwks_uri identifies a JSON Web Key Set (JWKS): a document containing keys that a verifier can use when checking signatures, subject to the verifier's issuer, algorithm, and key-selection rules.
A signed token may include a kid header that helps a verifier select a key. The verifier must still validate the signature and applicable claims, such as issuer, audience, and expiration. A matching kid, a readable JWKS, or a valid JSON document alone is not proof that a token is valid.
This distinction matters for APIs: an ID token and an access token serve different purposes. Confirm that the identity provider's documented access-token verification method, issuer, audience, and signing keys apply to your API; do not assume an ID-token configuration automatically validates access tokens.
The OpenID Connect discovery and JSON Web Key specifications are relevant to this workflow, but they were not available to consult in this run. Check your provider's documentation and the applicable specifications before relying on version-specific behavior.
Advertisement
Locate and check the JWKS URI
Use a non-production identity provider and a shell with curl and jq installed. The hostnames below are reserved examples, not working endpoints. Replace both values with the trusted non-production issuer and its discovery URL from your provider's configuration. Use the exact configured issuer, including any path and trailing-slash conventions.
Run the checks from a non-production workload or diagnostic environment with the same DNS, proxy, egress, and trust-store configuration as the API. The commands were not executed for this article.
1. Fetch and inspect discovery metadata
umask 077
ISSUER='https://idp.example/tenant'
DISCOVERY_URL='https://idp.example/tenant/.well-known/openid-configuration'
curl -sS --proto '=https' --connect-timeout 5 --max-time 15 \
-o discovery.json -w 'HTTP %{http_code}\n' "$DISCOVERY_URL"
Confirm that the printed status is 200 before proceeding. These commands do not follow redirects; a 3xx response needs investigation rather than being treated as a successful discovery response. A TLS, DNS, connection, or timeout error also needs investigation.
Check the issuer and extract the HTTPS JWKS URI:
jq -e --arg issuer "$ISSUER" \
'.issuer == $issuer and (.jwks_uri | type == "string" and startswith("https://"))' \
discovery.json >/dev/null || {
echo 'Discovery metadata failed the issuer or JWKS URI check' >&2
exit 1
}
JWKS_URI=$(jq -r '.jwks_uri' discovery.json)
printf 'JWKS URI: %s\n' "$JWKS_URI"
Review the hostname against the provider's trusted configuration before fetching it. The issuer comparison and HTTPS prefix check are useful diagnostics, not complete URL validation or proof that the endpoint is trustworthy. If discovery fails, do not substitute an issuer or hostname merely to make the check pass.
2. Fetch the key set
After confirming the URI is expected, request it without sending a token or other credentials:
curl -sS --proto '=https' --connect-timeout 5 --max-time 15 \
-o jwks.json -w 'HTTP %{http_code}\n' "$JWKS_URI"
Confirm a 200 status, then check that the response has a nonempty keys array:
jq -e '.keys | type == "array" and length > 0' jwks.json >/dev/null || {
echo 'Response is not a JWKS with a nonempty keys array' >&2
exit 1
}
This is a structural sanity check, not full JWK validation. An HTML error page, an empty key set, an unexpected key type, or keys that do not correspond to the token-signing configuration can all make verification fail. Even if both commands succeed, run the verification test below.
Treat downloaded files carefully: although a correctly published verification JWKS contains public keys, a misconfigured endpoint could expose sensitive material. Restrict access to the files, avoid uploading them to tickets or online tools, and remove them after troubleshooting. If private key material is exposed, follow your incident process and rotate the affected credentials; do not reproduce it in logs or examples.
Advertisement
Check rotation and actual verification
Test with a non-production token obtained through your normal authorized flow. Do not paste the token into a ticket, chat, shell history, or an online checker. Use your application's configured verification library and check its non-sensitive diagnostics.
- Confirm that the token's expected issuer and audience match the API configuration and that the token is intended for the API.
- Check whether the verifier can select an appropriate published key. If the token has a
kid, compare that identifier with the relevant published key identifiers without logging the token itself. Absence of akidrequires behavior appropriate to the provider and verifier; do not assume it is always an error. - Verify the signature with an allowed algorithm and validate the required claims. A key identifier is a selection hint, not an authorization decision.
- Exercise the provider's non-production rotation process if available. Confirm that the API can refresh its key set and accept an appropriately issued token after rotation, while still rejecting invalid tokens.
A provider can publish multiple keys during a transition. An old cached JWKS may lack a new signing key; an old discovery document may point to a retired hostname or URI. Conversely, immediately discarding older keys can disrupt verification of still-valid tokens. Coordinate overlap and cache behavior with the provider's documented rotation policy rather than assuming a fixed rotation schedule.
For an unknown kid, consider a controlled JWKS refresh followed by one verification retry. Rate-limit and deduplicate refreshes: attacker-supplied tokens with arbitrary key identifiers must not trigger unlimited outbound requests. Define bounded cache lifetimes and failure behavior for both discovery metadata and keys, and test those choices against your verifier and provider. Do not fall back to accepting an unverified token when refresh fails.
Diagnose common failures
| Symptom | What to investigate |
|---|---|
| DNS lookup or connection fails | Compare the published hostname with trusted configuration; check DNS, proxy, firewall, network policy, and egress from the API environment. |
| TLS verification fails | Check the hostname, certificate chain, system clock, and workload trust store. Do not disable certificate verification as a fix. |
| Discovery or JWKS returns a redirect or non-200 status | Check the configured URL and provider documentation. If redirects are intentionally supported, validate each destination and use a bounded redirect policy. |
| Response is reachable but not usable JSON | Inspect the status and content type; a proxy or gateway may be returning an error page. Avoid logging the entire response if it could contain sensitive material. |
| Key not found after rotation | Compare the token's non-sensitive key identifier with published keys; investigate stale discovery or JWKS caches and refresh policy. |
| Key exists but verification fails | Check algorithm policy, key compatibility, issuer, audience, token type, and time-related claims. Reachability does not isolate these failures. |
If your service automatically fetches discovery or JWKS URLs, treat that fetch as a security boundary. Use trusted issuer configuration and restrict allowed schemes and destinations. Account for DNS resolution and rebinding, redirects, and loopback, private, link-local, and other prohibited addresses where applicable. Enforce network egress controls, timeouts, and response-size limits. Parsing a URL or checking its hostname alone is not a complete server-side request forgery defense.
Common Mistakes
- Testing only from a laptop and assuming the deployed workload has the same network access.
- Treating HTTP
200, valid JSON, or a matchingkidas successful token verification. - Hard-coding a JWKS URI indefinitely without a plan for discovery changes or key rotation.
- Logging real tokens or copying key material into a support request.
- Disabling TLS verification or accepting an unverified token to bypass an outage.
- Using an ID token as an API access token without confirming the provider's intended validation rules.
Best Practices
Before release, run the discovery, endpoint, and verification checks in a representative non-production environment. Monitor discovery and JWKS fetch failures, cache refreshes, and verification errors without recording credentials. Document the trusted issuer, expected JWKS host, cache policy, and rotation contacts so the operations team can distinguish a network outage from stale metadata or a signing-key change.
Conclusion
A reachable JWKS endpoint is necessary for many verification setups, but it is not sufficient. Check the trusted discovery document, test the endpoint from the API's network, and exercise real non-production verification and rotation before release.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.