The idea: OAuth hands out a key, OpenID Connect says who you are
OAuth 2.0 lets an app act for a user: the app gets an access token
that an API accepts. That is authorization: what the holder may do. It does not tell the app
who the user is. OpenID Connect (OIDC) is a thin layer on top of OAuth that adds
authentication: who signed in. It adds one scope, openid, and one token, the
ID token, a signed statement made for the app itself. Every "Sign in with …" button works this way.
The canvas has three parties. alice's browser (with Eve, an attacker, under it), the app she signs in to, notes.example, called the relying party (RP), and id.example, the OpenID provider (OP), which knows her password. Under them are the ID token the RP holds and the five checks it makes on it. Orange boxes travel through the browser (the front channel), blue boxes go straight from server to server (the back channel), red ones are Eve's.
The authorization code flow with PKCE
OIDC uses the same authorization code flow as OAuth (Demo: sign in with OpenID Connect):
- alice clicks "Sign in with id.example". The RP makes three random values and keeps them in her session:
state(st-4Fq2),nonce(n-9xKp) and the PKCEcode_verifier(cv-T8wqLm). - It redirects the browser to
/authorize?response_type=code&scope=openid profile email&client_id=notes-web&redirect_uri=…&state=…&nonce=…&code_challenge=…&code_challenge_method=S256. The challenge isBASE64URL(SHA-256(code_verifier)); the verifier itself stays on the RP. - id.example checks the client and its exact
redirect_uri, asks for the password (only id.example ever sees it) and shows a consent page: "notes.example wants your name and email". - On Allow it redirects back to
https://notes.example/cb?code=c-Q7dR&state=st-4Fq2. The code is valid for a short time, once, and is tied to notes-web, the redirect URI, the challenge and the nonce. - The RP checks
state, then calls the token endpoint itself:POST /tokenwithgrant_type=authorization_code, the code, the redirect URI, thecode_verifierand its client credentials. - id.example checks that SHA-256 of the verifier equals the stored challenge and returns
{"access_token", "id_token", "token_type": "Bearer", "expires_in": 3600}.
PKCE makes a stolen code useless: whoever catches it in a redirect does not have the verifier. The
OAuth page shows that attack, and CSRF on the callback, which state stops.
The ID token
The ID token is a JWT (JSON Web Token): three base64url parts joined by dots,
header.payload.signature. The header names the algorithm and the key ("alg": "RS256", "kid": "k1").
The payload is a set of claims:
| Claim | Meaning | On the canvas |
|---|---|---|
iss | issuer: who made the token | https://id.example |
sub | subject: the user's stable id at that issuer | 248289761001 |
aud | audience: the client the token is for | notes-web |
exp, iat | expiry and issue time (seconds since 1970; shown as clock times) | iat + 1 h |
nonce | the value the RP sent in this sign-in's request, echoed back | n-9xKp |
The signature is made with id.example's private key. Anyone can check it with the matching
public key, which id.example publishes as a JWKS (JSON Web Key Set) at its jwks_uri;
the kid says which key to use. See Digital Signatures.
Checking the ID token
OIDC Core section 3.1.3.7 lists what the RP must check before it believes the token. The page shows the five that matter most, in the spec's order. Each one stops a different token Eve can bring:
| Check | Stops | Demo |
|---|---|---|
1 iss is the expected provider | a token from Eve's own provider, id.evil.example | forged tokens |
2 aud contains this client_id | a genuine token about alice that was made for another app | plain OAuth login vs ID token |
| 3 signature verifies with a JWKS key | a token whose payload was edited (sub changed) | forged tokens |
4 exp is in the future | an old token copied from a log | replayed tokens |
5 nonce equals the session's nonce | a still-valid token from a different sign-in | replayed tokens |
In the code flow the ID token comes straight from the token endpoint over TLS, so the spec lets the RP trust
the TLS connection instead of the signature. Libraries check the signature anyway, and it is required for an ID token
that arrives any other way, such as the /login endpoint Eve uses here (mobile apps often send the ID
token to their back end like this). After the checks, the pair (iss, sub) is the user's identity:
it never changes, unlike the email address.
userinfo and the access token
The access token has its own job. The RP sends it as Authorization: Bearer at-M2v9 to the
userinfo endpoint, an OAuth-protected API that returns profile claims for the granted scopes
(profile gives name, email gives email). The response's
sub must equal the ID token's sub. Then the RP starts its own session with a cookie and stops
using the tokens to recognise alice (JWT vs session cookies).
Why an access token is not a login
Before OIDC, many apps did "log in with OAuth": get an access token, call a profile API, sign in whoever it names. The access token was never meant for the app: it carries no audience the app checks. So any token for alice works, including one that alice once gave to an unrelated app (Demo: plain OAuth login vs ID token). Eve runs quiz.example; alice once signed in there, so Eve has alice's access token. She posts it to the plain-OAuth notes.example, /userinfo truthfully answers "this is alice", and Eve is signed in as alice. With OIDC Eve can only bring the ID token made for quiz-app, and check 2 refuses it.
| Access token (OAuth) | ID token (OIDC) | |
|---|---|---|
| Answers | what may the bearer do | who signed in, when, at which provider |
| Meant for | the API (resource server) | the client app (aud = client_id) |
| Format | opaque string or JWT, the client must not rely on it | always a signed JWT |
| Sent to APIs | yes, as Bearer | no |
Discovery and keys
An RP finds everything about a provider at https://id.example/.well-known/openid-configuration: the
issuer, authorization_endpoint, token_endpoint, userinfo_endpoint
and jwks_uri. It caches the JWKS. When the provider rotates its signing key, it publishes the new key
with a new kid first, so a token signed with an unknown kid makes the RP fetch the JWKS
again. Compare Kerberos, where single sign-on inside one network uses symmetric keys
shared with the KDC instead of public keys, and passkeys, which can replace the
password at the provider.
See also How SAML Single Sign-On Works for the older XML-based single sign-on, with Audience, NotOnOrAfter and InResponseTo in place of aud, exp and nonce.
What the page leaves out
- Real cryptography: codes, hashes and signatures are short fake strings, and TLS under every request is not drawn.
- The other ID token checks (
azpwith several audiences,iatlimits,auth_timewithmax_age,acr), encrypted ID tokens, and the implicit and hybrid flows. - Refresh tokens, logout (RP-initiated, front- and back-channel logout),
promptandlogin_hint, dynamic client registration. - How the provider checks the password or a second factor, and the consent screen's remembered choices.