OpenID Connect sign-in and the ID token, step by step
OpenID Connect sign-in in eight steps on archhy's diagram, the claims inside the ID token, and the checks before you trust it.
Diagrams in this video · 1Free in archhy
The diagrams, full size
Copy any of them into archhy, free, and change it for your own system.
After this lesson you can
- Say what OpenID Connect adds to OAuth 2.0
- Walk an OpenID Connect sign-in in eight steps
- Read the required claims in an ID token
- Validate an ID token before trusting it
Transcript
OpenID Connect sign-in and the ID token, step by step
Space Llama here. OAuth tells an app what it may do. It doesn't tell the app who you are. That's OpenID Connect. Today: signing in, and the token that proves who signed in.
What OpenID Connect adds
OpenID Connect renames two parties. The authorization server becomes the OpenID provider. The client becomes the relying party, because it relies on the provider to say who you are. Then it adds a few small things. The openid scope: put it in the request, and an OAuth request becomes an OpenID Connect sign-in. An ID token: a signed JSON Web Token, returned beside the access token. A UserInfo endpoint, an API that returns claims about you. And discovery: one document that lists the provider's endpoints and keys, so an app can be set up from the issuer address alone.
Signing in, step by step
It's the authorization code flow with PKCE, the Proof Key for Code Exchange, from lesson two, with the OpenID Connect parts added. One. You click Sign in in the app. Two. The app redirects your browser to the authorize endpoint with scope openid, a state, a nonce, and a PKCE code challenge. Three. The provider authenticates you. A password, multi-factor sign-in, a passkey, or a session you already have. Four. The browser comes back to the app with a code and the state. Five. The app posts the code and the code verifier to the token endpoint. Six. The provider returns an ID token and an access token, and possibly a refresh token. Seven. The app validates the ID token, and starts its own session for you. Eight. Optionally, it calls UserInfo with the access token, for claims that weren't in the ID token.
Inside the ID token
Decode the middle part of an ID token, and you get a small set of claims. Five are required. Iss, the issuer: the provider's exact address. Sub, the subject: a stable identifier for you at that issuer. Use issuer plus subject as the user's key. Never the email address, which can change, or be reused. Aud, the audience, which must contain the app's own client ID. And exp and iat: when it expires, and when it was issued.
Validate it before you trust it
An ID token only proves anything once the app has checked it. The signature must be valid, using a key from the provider's JSON Web Key Set, with the algorithm you expect. The issuer must match exactly. The audience must contain your client ID. The current time must be before the expiry, allowing a little clock skew. And the nonce must match the one you sent in step two. That stops an old token being replayed into a new sign-in. Use a maintained OpenID Connect library for this. Most mistakes here are skipped checks.
Remember
Let's recap. Add the openid scope, and the same code flow with PKCE becomes a sign-in, with an ID token back. Key your users by issuer plus subject. And validate every ID token: signature, issuer, audience, expiry and nonce.
Your turn in archhy
Open this flow in archhy and change it for your own system. The link is below, with archhy's full article. Next lesson: which token goes where, and signing out. See you there.
Draw it in archhy
Open this lesson's diagram in archhy, ready to change for your own system. Free, in the browser.





