Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Following a complete sign-in

Much of an OpenID Connect sign-in will look familiar from the connection traced in Why use the authorization code flow?, because OpenID Connect reuses the authorization code flow. 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 party 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 OAuth 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/callback

When 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 lifetime

The only new line is the nonce. The collage app will ask the photo service to copy it into the ID token, so that it can tell later that the token 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 authorization 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=S256

The 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 session 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-store

Back 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 issuer, and claims the attempt so it can't be processed twice.

Its backend then exchanges the code at the token endpoint, with the PKCE 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.

The exchange is the authorization code flow. OpenID Connect adds the nonce, the ID token, and the collage app's work after the token response: validating the token and starting a session of its own.

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.

Compared with connecting a photo account, which step is new in an OpenID Connect sign-in? 1 of 2

Choose one answer.

The photo service has signed Ava in and redirected her browser back. The collage app has not yet exchanged the code. Is Ava signed in to the collage app? 2 of 2

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity