Receiving the ID token
Ava's browser has returned to the collage app's sign-in callback, and the collage app has matched the response to its pending attempt. It holds an 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., and it still doesn't know who Ava is. This lesson follows the code to 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. and reads what comes back.
The token request
The collage app's backend exchanges the code exactly as the printer did when connecting Ava's photo account. Nothing in this request is specific to OpenID ConnectAn 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., and all domains, credentials, codes and tokens in these examples are fictional:
POST /token HTTP/1.1
Host: auth.photos.example
Authorization: Basic cGhvdG8tY29sbGFnZTpkZW1vLW9ubHktbm90LWEtcmVhbC1zZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=demo-code-12
&redirect_uri=https%3A%2F%2Fcollage.example%2Fsignin%2Fcallback
&code_verifier=btl_training_verifier_for_one_sign_in_only_2026The photo service makes the same checks as before: the collage app's client authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do., the code's binding to this client and redirect URI, its expiry and single use, and the PKCEProof Key for Code Exchange, pronounced pixie: the client creates a secret for each authorization attempt, sends only a hash of it at the start, and proves it holds the secret when redeeming the code, so a stolen authorization code is useless to anyone else. proof. Exchanging a code for tokens walked through each of them.
What differs is what the code stands for. Because the original request included openid, the photo service recorded the code as belonging to a sign-in, along with the nonceA random value used for one attempt only. In OpenID Connect, the client sends one in its sign-in request and checks that the same value comes back inside the ID token, showing the token answers this attempt. from the request and the time Ava authenticated. Those are what it needs to write the 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..
The token response
A successful response looks like this. The ID 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.'s signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. is shortened for display, and a real RS256 signature is several hundred characters long:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token": "demo-access-token-12",
"token_type": "Bearer",
"expires_in": 600,
"scope": "openid profile email",
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InBob3Rvcy1ycy0yMDI2LTA5IiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2F1dGgucGhvdG9zLmV4YW1wbGUiLCJzdWIiOiJ1c2VyLTIwNDgiLCJhdWQiOiJwaG90by1jb2xsYWdlIiwiZXhwIjoxNzkwODQ1NTAwLCJpYXQiOjE3OTA4NDUyMDAsImF1dGhfdGltZSI6MTc5MDg0NTE4NSwibm9uY2UiOiJkZW1vLW5vbmNlLTMifQ.Rk3v...shortened"
}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., token type, lifetime, and scope are the familiar 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. fields. This access token was issued for openid profile email, so it does not let the collage app read Ava's photos. Its use is at the photo service's UserInfo endpointAn OpenID Provider endpoint that returns claims about the signed-in person to a client presenting an access token. Its sub must match the ID token's before the client uses anything it returns., which The UserInfo endpoint describes.
The id_token is a JWT in its compact form: three Base64url-encoded segments separated by dots. Decoding the first segment gives the header, and decoding the second gives the claims, exactly as shown in ID tokens and access tokens:
{"alg":"RS256","kid":"photos-rs-2026-09","typ":"JWT"}
{"iss":"https://auth.photos.example","sub":"user-2048","aud":"photo-collage",
"exp":1790845500,"iat":1790845200,"auth_time":1790845185,"nonce":"demo-nonce-3"}The line break in the second segment is for display. The third segment is the signature, which the photo service computed over the first two segments exactly as they appear, joined by their dot.
Before trusting it
Decoding those segments needed no key and proved nothing. Anyone can produce text that decodes to "sub":"user-2048". As Protecting credentials and messages put it, reading is not validating. Until the collage app has checked the signature with the photo service's key and compared the claims with what it expects, the token is only a statement that someone sent.
One nuance appears in the specification and in some libraries. This token came straight from the photo service's token endpoint, over a TLS connection that the collage app's backend opened itself after validating the server's certificate. OpenID Connect allows a relying party in that position to rely on the connection to establish who issued the token, instead of verifying the token's signature, because no one else handled it on the way. This series verifies the signature anyway. It costs little, it gives the collage app one validation path for every ID token it accepts, and it stays correct if the token is later stored, passed between components, or presented again. The other checks, including issuer, audience, lifetime, and nonce, are required either way.
Two habits keep the token in its place. The collage app keeps the ID token on its backend, out of responses sent to the browser and out of its logs. It also never uses the ID token as its own session: no cookie containing the token, and no API that accepts it as proof of a signed-in customer. Once validated, the token's job is to start a session. Some relying parties keep it on the server afterward, because a later sign-out request can include it as a hint, as RP-initiated logout explains.
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
- Send the token request yourself and take the response apartRedeem a sign-in code with curl, read every header and field of the token response, and see that a real ID token issued to another client decodes just as cleanly as yours.