Following a complete sign-in
Much of an 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. sign-in will look familiar from the connection traced in Why use the authorization code flow?, because OpenID Connect reuses the authorization code flowThe main OAuth flow: the browser visits the authorization server, where the person signs in and approves access, then carries an authorization code back to the client, which exchanges it for tokens directly. When the client runs on a server, the tokens never pass through the browser.. Following one sign-in at the collage app from start to finish shows which steps are the same and where the new ones fit.
Choosing Continue
Ava opens the collage app on a Thursday morning, 1 October, to start a new poster. She is not signed in. On the sign-in page, she selects Continue with your photo account. All domains, credentials, codes and tokens in these examples are fictional. Fixed, readable values make the example easy to follow; a real 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. generates fresh, unpredictable values for every attempt.
Before any of this can happen, the collage app's registration with the photo service needs a return address for sign-in. If the collage app also connects photo accounts for access, that still returns to its 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. callback. Signing in returns to an address of its own, so the collage app handles the two kinds of attempt separately:
Client ID: photo-collage
Redirect URIs:
https://collage.example/oauth/callback
https://collage.example/signin/callbackWhen Ava selects Continue, the collage app creates a pending sign-in, much like the pending connection the printer created in the OAuth lessons. It records what this attempt will need later:
Pending sign-in: demo-signin-3
Initiating session: the current, not yet signed-in collage session
Expected issuer: https://auth.photos.example
Redirect URI: https://collage.example/signin/callback
Nonce: demo-nonce-3
PKCE verifier: held privately on the backend
Return destination: the new poster page Ava was viewing
Status: pending, with a limited lifetimeThe only new line is 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.. The collage app will ask the photo service to copy it into 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., so that it can tell later that the 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. belongs to this attempt. State and nonce explains how the two values divide the work.
At the photo service
The collage app redirects Ava's browser to the photo service's authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. endpoint. The request includes openid in its scope:
https://auth.photos.example/authorize
?response_type=code
&client_id=photo-collage
&redirect_uri=https%3A%2F%2Fcollage.example%2Fsignin%2Fcallback
&scope=openid%20profile%20email
&state=demo-signin-3
&nonce=demo-nonce-3
&code_challenge=VJLVyms6-H5HoRQD_d-b-XThm8LNqfrMav0hDI23zpU
&code_challenge_method=S256The authentication request reads it parameter by parameter. For now, notice that it asks for sign-in and for Ava's basic profile and email address, and says nothing about her photos.
The photo service checks the request against the collage app's registration, as it would any authorization request. Then it establishes who is in the browser. If Ava signed in to the photo service earlier and its 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. is still valid, it may not need to ask her for anything. Otherwise she signs in there, with whatever methods her photo account uses. The collage app never sees them.
The photo service may also ask whether Ava is willing to share her profile and email address with the collage app. If she agrees, or agreed on an earlier visit, it sends her browser back:
HTTP/1.1 302 Found
Location: https://collage.example/signin/callback?code=demo-code-12&state=demo-signin-3&iss=https%3A%2F%2Fauth.photos.example
Cache-Control: no-storeBack at the collage app
Everything so far could have been an OAuth connection, and the collage app handles the callback in the same way. It finds the pending attempt using state, checks that the attempt belongs to this browser's session, compares iss with the expected issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts., and claims the attempt so it can't be processed twice.
Its backend then exchanges the code at 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., with 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. verifier and its client authentication. The response is where OpenID Connect becomes visible. Alongside the access token, it contains an id_token.
The collage app validates that ID token before believing anything in it. It verifies the signature with the photo service's published key, confirms that the issuer is the photo service and the audience is photo-collage, checks that the token is within its lifetime, and checks that its nonce is demo-nonce-3. Validating an ID token takes these checks one at a time.
Only then does the collage app use what the token says. It looks for a collage account linked to user-2048 at https://auth.photos.example, the issuer and subject together. If there is one, that is Ava. If not, this is her first visit, and the collage app creates an account or asks her to finish registering. Connecting a sign-in to an account covers both paths.
Finally, the collage app starts a session for Ava with a new session identifier, rather than giving the anonymous one access to her account, and redirects her browser from the callback address to the poster page. The callback URL, with its code, does not stay in the address bar.
Compared with connecting a photo account, the request gained openid and a nonce, the token response gained an ID token, and the collage app gained two jobs: validating that token and turning it into a session of its own. Until both are done, Ava is not signed in to the collage app, even though the photo service already shows her as signed in.
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 a complete OpenID Connect sign-in, one message at a timeCreate a pending sign-in, send the authentication request, handle the callback, redeem the code and start your own session, then watch single sign-on and a replayed code.