OIDC ID Token Validation Errors and How to Test Them

Six ways ID tokens fail validation, and how to reproduce each.

· 11 min read · Updated
Cover illustration for “OIDC ID Token Validation Errors and How to Test Them”
OAuth and SSO Flows · October 13, 2026 · 11 min read · 2,401 words

OIDC ID token validation is a sequence of gates, and a token has to clear each one in order before a relying party can trust the claims inside it. OIDC Core 1.0 Section 3.1.3.7 lays out that order: issuer, then audience, then signature, then expiry and not-before, with nonce checked separately in flows that use one. Skipping a gate or checking them out of sequence is a common mistake on its own, and it tends to hide the real failure behind a more confusing one. A token can be a perfectly well-formed JWT, with three base64 segments and a valid structure, and still fail every one of these checks. Parsing a token tells you it's shaped correctly. It tells you nothing about whether it was issued by the right party, for the right audience, signed with the right key, still valid in time, or tied to the right authentication request. If a relying party confuses those two things, structural validity and semantic validity, it will eventually accept a token it should have rejected. The ID token is scoped to the relying party client that requested it. It is not an access token, and forwarding it to a resource server or another downstream service breaks the model the gates were built to enforce.

The six named failure modes

Issuer mismatch happens when the iss claim in the token doesn't exactly match the issuer URI the provider has configured, and the match has to be exact: even a trailing slash will cause validation to fail. This occurs often in Workload Identity Federation setups when a team moves a workload between staging and production and the issuer URIs differ between environments, or when a self-hosted identity provider and a cloud-hosted one use different issuer values for what looks like the same logical service. The issuer check runs first, so you usually just see a flat rejection before any claim processing happens.

Audience mismatch happens when the aud claim doesn't match what the relying party expects to see. Duo's documentation for Single Sign-On with OIDC describes a concrete version of this: when the Client ID configured on the Relying Party doesn't match the Client ID set in the Duo Admin Panel, the result is a "Request was malformed" error. The broader point behind this failure mode is that a signed, authentic token isn't automatically trusted just because it came from the right identity provider. In multi-tenant or federated setups, a token can be genuinely issued by the correct provider and still be wrong for the specific client or trust boundary trying to use it.

Token expiry and clock skew cover a cluster of related triggers: a real gap between the clock on the issuing server and the clock on the validating server, a cached token that gets reused past its expiration, or network latency that lets a short-lived token expire in transit before the request completes. The standard mitigation is to keep every host, issuer and validator, synchronized with NTP, and to configure a leeway window on the validator so small residual skew doesn't cause false rejections. In gRPC services specifically, an expired token produces a Status.UNAUTHENTICATED response before the request ever reaches the service's own logic.

Invalid or rotated signature keys cause failure when the JWKS URL configured on the relying party doesn't match the JWKS URL the identity provider actually serves. Without the matching public key, the relying party can't verify the token's signature. The adjacent and more dangerous version of this failure is a relying party that accepts alg: none. An unsigned token can pass structural checks cleanly, but it should never pass signature verification, and a relying party that doesn't enforce this distinction has a real hole in it.

Nonce mismatch and replay is the one failure mode you only see in interactive, browser-based flows. The nonce ties one authentication request to one response. Without checking it, a relying party can be handed a previously valid token and treat it as a fresh, legitimate login, turning a stale response into an unauthorized session.

Missing or mismatched claim mapping comes up when an attribute mapping references a claim the token doesn't actually contain, such as a mapping pointing at assertion.repository on a token that has no such field. The fix is mechanical: decode the token and confirm every claim the mapping references is actually present. A related trigger is an attribute condition, written as a CEL expression, that fails to evaluate true, such as assertion.repository_owner == 'your-github-org' failing with an explicit "attribute condition was not met" error when a workflow runs from a fork or a different organization than the one the condition expects.

Why These Failures Are Hard to Reproduce

Knowing these six failure modes by name is not the same as being able to produce any one of them on demand, and that gap is where most of the real engineering effort goes. Most of them simply cannot be triggered reliably against a live identity provider, because the test has no control over token timestamps, no control over when a key rotation happens, and no control over the provider's own issuer configuration.

Clock skew is the clearest case. Testing it means creating a timing condition between two clocks you don't own when the provider is live, and there's no way to freeze or advance time on someone else's identity service. Key rotation is worse: reproducing the failure means triggering an actual rotation event and then catching the narrow window where the relying party might select the wrong key, which isn't something you can do repeatably against a shared staging environment or a production identity provider without disrupting everyone else using it. Nonce replay has its own problem: testing it means issuing a token and resubmitting it, but a live identity provider tracks nonce state globally, so the test itself pollutes shared state that other sessions depend on. Issuer and audience mismatches require changing the provider's actual configuration, which affects every other consumer of that provider in a shared environment, not just the test in question.

Diagnosis doesn't get easier once a failure happens. Google's own troubleshooting documentation for Workload Identity Federation lists a range of distinct STS error messages tied to specific validation failures, but even with that range covered, root-cause isolation from a live failure can still take real digging, because the error returned at the moment of failure doesn't always point cleanly back to which of the six gates actually rejected the token. OIDC flows are multi-step, moving through authorization, then token exchange, then an optional userinfo call, and that multi-step structure is what produces this diagnostic difficulty. A failure that appears at the token exchange step often depends on state that was established back at the authorization step, and a stateless approach to testing, one that just fires off a request and checks the response, cannot model that dependency chain.

What a Test Environment Needs

Reproducing all six failure modes on demand means building (or using) a test environment that owns the entire token lifecycle. That environment has to be able to issue tokens with arbitrary claim values, including deliberately wrong ones, so that issuer and audience mismatches can be constructed directly. It needs the ability to issue tokens signed with a known key and also with a rotated or mismatched key, so the signature validation path can be exercised directly, and it needs the ability to issue an alg: none token specifically to confirm the relying party rejects it, catching cases where it would otherwise quietly accept an unsigned payload.

The test has to control time as a variable. The environment needs to issue a token with an exp value already in the past without requiring the test to sit around until real time catches up, and it needs to simulate a skewed iat that differs from the validator's clock by a configurable margin, so the leeway-window behavior can actually be exercised.

Key rotation needs to be something the environment can stage on command. It has to serve a JWKS endpoint whose key set can change mid-test, simulating a real rotation event, so you can confirm the relying party fetches the updated keys correctly. It also needs to serve a JWKS endpoint that deliberately returns an outdated or mismatched key, which is the shape of bug HashiCorp documented in Terraform Enterprise versions v202207-1 through v202406-1, where a code path sorted key versions lexicographically, as text, instead of numerically, and ended up selecting an older key than the one actually in use.

None of this works without memory. The environment has to remember the nonce issued during the authorization step so it can recognize and reject a replay attempt later in the flow, and it has to track which tokens have been issued, exchanged, and invalidated over the course of a test. A stateless stub that just returns the same hardcoded object every time cannot enforce any of these transitions, because it has no memory of what came before in the flow.

Finally, the environment needs to misbehave on command at the provider level. It has to be able to make the JWKS endpoint slow, return a 503, or hand back an unexpected payload, so the test can confirm the relying party handles provider unavailability by failing closed, catching cases where it would otherwise silently accept an unverified token. And it needs to make the token endpoint return a 429, so retry and backoff logic can actually be exercised.

A testing strategy that covers all six failure modes systematically

Once a simulator can stand in for the identity provider and supply all of the above on command, each of the six failure modes becomes a deterministic test case with a clear setup, a clear trigger, and a clear expected result, run without touching anything live.

The issuer mismatch test configures the simulator to issue a token with an iss value that differs from what the relying party expects, whether that's a trailing slash added to an otherwise identical URL or a staging URL substituted for a production one. The expected outcome is a rejection that happens before any claim processing takes place, confirming the relying party doesn't fall through to audience or signature checks on a token that already failed at the issuer gate.

The audience mismatch test issues a token with an aud value pointing at a client ID that doesn't match the relying party's configured client ID, and checks that the token is rejected rather than accepted because it came from a trusted provider. A second version of the same test issues a token missing a claim the attribute mapping expects, such as a repository claim the mapping references but the token doesn't carry, and confirms the mapping check fails explicitly.

The expired token test issues a token with an exp value already set in the past, with no need to wait for real time to pass, and confirms the relying party returns an authentication error rather than caching and reusing a token that's already stale. A second version issues a token with a future expiry, advances the simulator's internal clock past that point, and makes a second call to confirm the relying party correctly treats the now-expired cached token as invalid.

The signature and key rotation test issues a token signed with one key, then rotates the simulator's JWKS endpoint so it serves only a second, different key, confirming the relying party fetches the updated key set and rejects the token signed under the old one. A second case serves a JWKS response that omits the signing key entirely, confirming the relying party doesn't accept the token when no matching key can be found. A third case issues a token using alg: none, confirming the relying party rejects it, treating the unsigned payload as invalid.

The nonce replay test runs a complete browser-based flow from authorization through token issuance, captures the resulting ID token, and then submits that same token a second time in a new session. Because the simulator is stateful, it has already marked that nonce as consumed, and the expected result is a rejection on the second submission. This test only works at all because the simulator remembers the first flow; a stateless stub has no record of it to check against.

The fault injection tests cover provider misbehavior directly. One configures the simulator to return a 503 from the JWKS endpoint during signature verification, confirming the relying party fails closed by default. A second injects latency into the JWKS endpoint to confirm timeout handling actually triggers. A third has the token endpoint return a 429, confirming the relying party's retry and backoff logic behaves as designed rather than failing immediately or retrying without limit.

These tests hold together as a suite when each one resets the simulator's state before it runs, so nonce state, key sets, and previously issued tokens from one test don't leak into the next and produce a false result. Valid-token tests belong in the same suite as these failure-mode tests: a regression that breaks normal authentication is just as serious as one that starts accepting tokens it should reject, so running both together catches either kind of break in the same pass. All of this belongs in CI: it runs against a local simulator, needs no live credentials, and finishes in seconds regardless of whether the real identity provider is up, slow, or rate-limiting that day.

The fault injection behavior, the slow JWKS endpoint, the 503 on signature verification, the 429 on token exchange, works as direct configuration on the simulator rather than something bolted on through a separate proxy. Keeping the simulator's token structure, claim names, and endpoint behavior checked against the real provider's current behavior before each release matters too: it's how drift between the simulated provider and the real one gets caught in the test suite. Because everything runs locally or in CI without live credentials or rate limits, you can turn clock control and key rotation scenarios that are simply impossible to construct against a live identity provider into ordinary, repeatable test cases against a simulator built to allow them. The same setup extends naturally to teams building AI agents that call services sitting behind OIDC, where an agent has to handle a token expiring mid-session or re-authenticate cleanly after a 401: the deterministic, resettable environment this testing strategy depends on is what agent evaluation and reinforcement learning training need as well.

Sources

  1. Troubleshoot OAuth/OIDC Issues on Confluent Cloud

More in OAuth and SSO Flows