Validating an ID token
An ID tokenIn OpenID Connect, a signed JWT from the provider, addressed to one client, saying which account authenticated, when, and in answer to which request. It reports a sign-in and is not used to call APIs. that arrives in a successful tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. response still proves nothing until the relying partyAn application that accepts and relies on a sign-in from another service, the name used in OpenID Connect and for passkeys. SAML calls the same role a service provider. has checked it. This lesson follows the collage app through every check, in order, and what it keeps once they pass.
Before reading the claims
Authentication errors followed sign-ins that fail in plain view: an error in the redirect, or a token response with no ID token in it. This time the collage app's token request at 09:00 UTC on 1 October succeeds, and the response carries an ID token saying that Ava Archer, photo account user-2048, has just signed in at the photo service. All domains, identifiers and tokens in these examples are fictional.
Nothing about it looks wrong, but looking right is easy: anyone able to put a string in that position can manage it. The collage app needs to establish four things before it believes a word: that the photo service issued this token, that it was issued to the collage app, that it answers this sign-in attempt, and that it is current.
Here is the token, decoded:
Header
{
"alg": "RS256",
"kid": "photos-rs-2026-09",
"typ": "JWT"
}
Claims
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "photo-collage",
"exp": 1790845500,
"iat": 1790845200,
"auth_time": 1790845185,
"nonce": "demo-nonce-3"
}Until every check has passed, these are statements the collage app has not confirmed. It does not look up an account for user-2048, create a sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier., or greet Ava by name. It also leaves the access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in. from the same response untouched. If an attacker managed to slip another person's authorization codeA short-lived, single-use value that the authorization server sends back to a client through the browser. The client swaps it for tokens in a direct request to the authorization server; APIs never accept it. into this exchange, both tokens in the response came from that code, and the ID token checks are how the collage app finds out. Current OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. security guidance says so directly: a client that relies on the nonce to detect injected codes must not use any token from the response, the access token included, until the nonce check has succeeded.
As Receiving the ID token explained, the collage app verifies the signature even though the token came straight from the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect. over a connection it opened itself.
Much of what follows is familiar. Token formats and validation walked the photo APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. through the checks for a JWTA JSON Web Token: a compact token made of Base64url-encoded parts that carries claims and is usually signed. Anyone holding it can decode and read the claims, so the signature shows who issued it but hides nothing. access token, and Digital signatures explained why the algorithm and key identifier in a header are only hints. An ID token is also a JWT, signed by the same provider. What changes is who it is for and what it has to prove:
| Check | JWT access token at the photo API | ID token at the collage app |
|---|---|---|
| Algorithm | ES256, the algorithm the photo service uses for access tokens. | RS256, the OpenID Connect default, unless the client registered another. Choosing and enforcing algorithms explained both names. |
| Type | typ must be at+jwt. | The core specification defines no type for ID tokens. JWT says only that this is a JWT, and some providers leave typ out. |
| Audience | The API's identifier, https://api.photos.example. | The client ID, photo-collage. The collage app's own rule adds that an azp (authorized party) claim, which names the client that asked for the token, must also name photo-collage if one appears. |
| Link to a request | None. Any request may carry the token until it expires. | nonce must equal the value stored with this sign-in attempt. |
| Authentication details | Checked only by an API that demands a recent or stronger sign-in. | auth_time and acr, the authentication context class reference that Authenticator assurance levels introduced: the provider's name for how strongly the person signed in. Both are checked when the collage app asked for them. |
The type row protects only one side. The photo API's at+jwt check stops an ID token from being used as an access token, but nothing in an ID token's header stops other JWTs from being offered to the collage app as ID tokens. The audience and the nonce carry that weight instead: a JWT addressed to anyone else, or produced for any other attempt, fails there.
The checks in order
The collage app found this attempt when Ava's browser returned with state demo-signin-3, and the attempt recorded what the collage app expects: the issuer https://auth.photos.example, the nonce demo-nonce-3, and anything it asked for about how Ava authenticates. Those stored values, not the token's own claims, decide which provider's settings apply. The collage app then works through the token:
- Accept only an expected algorithm. The header's
algmust be on the collage app's list for ID tokens from this provider, which here holds onlyRS256. - Find the key.
kid, herephotos-rs-2026-09, must name a key in the photo service's key setA JSON document, published at a fixed HTTPS address, that lists an issuer's current public keys so others can verify its signatures. It never contains private keys., and that key must suit the algorithm. Signing keys and rotation covers these first two steps. - Verify the signature over the exact bytes of the header and claims.
- Check the issuer.
issmust equal the expected issuer exactly. - Check the audience.
audmust containphoto-collageand no audience the collage app does not trust. The collage app also applies a rule of its own: if anazpclaim is present, it must bephoto-collage. Issuer, audience, and authorized party covers these claims, and explains why the specification leaves theazpcheck to each relying party and why the collage app chooses this rule. - Check the time. The current time must be before
exp, allowing a small tolerance for clock differences, andiatmust be recent. - Match the nonce.
noncemust equaldemo-nonce-3. A token without one fails. - Check the authentication, if the collage app asked. When the request set
max_ageor asked for a particular authentication context,auth_timeandacrmust satisfy it. Expiration and nonce checks covers this step and the two before it.
A relying party that registered to receive encrypted ID tokens decrypts first. The collage app has not, and Signed and encrypted messages, in Advanced OIDCAn identity layer on top of OAuth 2.0 that lets an application sign people in with an account at another service. It adds the ID token, standard claims, and discovery to the OAuth exchange., covers that case.
The specification lists the issuer and audience checks before the signature. The order matters less than the rule that every check runs and nothing is used until all of them have passed. Verifying the signature early has one advantage: every later comparison is made against values the photo service actually signed.
attempt = pending_sign_in # found by state, bound to this browser
provider = providers[attempt.expected_issuer] # https://auth.photos.example
header, claims, signature = parse(id_token) # nothing here is trusted yet
if header.alg not in provider.id_token_algorithms: # ["RS256"]
reject("algorithm")
key = provider.key_set.find(header.kid) # photos-rs-2026-09
if key is None or not key.usable_with(header.alg):
reject("key")
if not verify(key, header.alg, signed_bytes, signature):
reject("signature")
if claims.iss != provider.issuer:
reject("issuer")
if provider.client_id not in audiences(claims.aud) or has_untrusted_audience(claims.aud):
reject("audience")
if claims.azp is present and claims.azp != provider.client_id: # the collage app's own rule
reject("authorized party")
if now() >= claims.exp + LEEWAY or not recent(claims.iat):
reject("time")
if claims.nonce != attempt.nonce: # a missing nonce fails too
reject("nonce")
if attempt.max_age is set and too_old(claims.auth_time, attempt.max_age):
reject("authentication age")
accept(claims) # only now find the accountEvery reject ends the sign-in. The attempt has already been claimed, so it cannot be tried again, no account is looked up, and no session is created. When validation fails follows what the person sees next and what the collage app records.
As with access tokens, a maintained OpenID Connect library performs these checks for the collage app. The collage app's part is to give it the expected issuer, client ID, algorithms, and key set, to pass in the nonce from the attempt, and to confirm that the library rejects a token with a missing value rather than skipping the check.
What the collage app keeps
Once the last check passes, the token has answered its question: who signed in, for this attempt, and how. The collage app keeps the answer, not the token.
The issuer and subject together, https://auth.photos.example and user-2048, identify Ava's photo account, and the collage app uses that pair to find her collage account, as Connecting a sign-in to an account describes. It records auth_time, and acr when there is one, with the session it is about to create, so that later decisions about sensitive actions know how recent and how strong this sign-in was.
The nonce is finished. It left with the pending attempt when the collage app claimed it, so no later token can match it. Nor does the token's five-minute lifetime carry over. As ID tokens and access tokens explained, exp limits when the collage app may accept the token, not how long Ava stays signed in.
The ID token itself stays on the collage app's server only if the collage app will need it again, as a hint in a later sign-out request. It never goes into a cookie, a page, or a log.
The access token can now be used. The collage app asked for profile and email, and with the code flow those claims come from the UserInfo endpoint, which the collage app calls with demo-access-token-12. The UserInfo endpoint describes that call and the subject check that goes with it.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Run every ID token check in order and keep only the answerConfigure an ID token verifier from your own expectations, watch it run the lesson's checks in order on a real token, make it refuse missing settings, and keep the issuer and subject, not the token.