Beta

Create a tenant

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

From delegated access to sign-in

The OAuth lessons gave applications access to Ava's photos. Signing her in to an application is a different request, and the access token is the wrong answer to it. This lesson follows the collage app as it adds a sign-in button, sees why an access token can't sign anyone in, and meets what OpenID Connect adds.

A new button

Ava uses a collage app that turns her photos into posters. Every new customer has to create a collage account before making one: choose an email address, invent a password, confirm the address. Plenty of people give up halfway, and most of them already have an account at the photo service. All domains, identifiers and tokens in these examples are fictional.

The collage company would like to add a button to its sign-in page: Continue with your photo account. Ava would select it, prove who she is to the photo service the way she always does, and arrive back at the collage app signed in. There would be no new password for her to remember, and none for the collage app to store.

This is a different request from the one the OAuth lessons followed. There, from The problem OAuth solves onward, the printer wanted access: permission to read Ava's photos. Now the collage app wants to know who is using it. More precisely, it wants a trustworthy answer to one question. Has the person in this browser just authenticated at the photo service, and if so, as which photo account?

The collage app already knows how to send a browser to the photo service and get something back, because the authorization code flow does exactly that. It is tempting to reuse that exchange as it is.

Why an access token is not a sign-in

Here is the shortcut. The collage app runs the authorization code flow, receives an access token, and calls an endpoint on the photo API that describes the account behind the token:

GET /me HTTP/1.1
Host: api.photos.example
Authorization: Bearer demo-access-token-12

HTTP/1.1 200 OK
Content-Type: application/json

{ "id": "user-2048", "name": "Ava Archer" }

The collage app then signs in whoever owns user-2048, Ava's account. It works in a demonstration, and it answers the wrong question.

An access token tells the photo API that some client may read some photos. It was written for the API, and the client only carries it. Nothing in the token, or in the API's answer, tells the collage app that this token was issued to the collage app, for this sign-in attempt, a moment ago.

That gap matters as soon as a token can reach the collage app from somewhere other than its own token request. Suppose the collage app's phone app runs the flow itself and sends the access token it receives to the collage backend, which signs in the account behind it. Ava has also connected the printer to her photo account, so the printer holds a valid access token for her photos. Its operator, or anyone who copies that token, can send it to the collage backend in place of a token from the collage phone app. The backend calls /me, receives user-2048, and signs that person in as Ava. The token is genuine. It was simply never meant for the collage app. This is the access token injection that The implicit grant described, arriving by a different route.

The photo API correctly accepts a token issued to another app, so a backend that trusts /me signs the wrong sender in. An ID token names the client it was issued to, so the same move fails.

Time is a second problem. An access token can be issued long after anyone last authenticated. In The refresh token grant, the printer obtained new access tokens every December without Ava being present. A token like that shows that an authorization still exists, not that anyone has signed in recently.

The third problem is practical. Every service that offered a /me endpoint designed its own, with its own field names and its own idea of what an identifier was. An application that wanted to support several services had to learn each one, and it still couldn't tell from any of them when or how the person had authenticated.

Many early "sign in with" integrations were built this way. Their problems are the reason a separate standard exists.

What OpenID Connect adds

OpenID Connect, often shortened to OIDC, adds an identity layer to OAuth 2.0. It keeps the authorization code flow you already know, with the same endpoints, state, PKCE and code exchange, and adds a small number of things on top. A client asks for it by including the scope openid in its authorization request.

The new piece is the ID token, a signed JWT from the photo service about one sign-in. It names the service that made the statement, an identifier for Ava's photo account, the client the statement is for, and how long it stays acceptable. The collage app checks it against what it already knows about the photo service before it looks up any account. The access token keeps a different job: it lets a client call an API. Even an access token written as a JWT that happens to mention a client is not an ID token, because it was written for the API, not for the client.

Each detail of the ID token closes one of the gaps above. Because the token is addressed to the collage app, an ID token issued to the printer names the printer, and the collage app refuses it. Because it can carry a value the collage app chose for this attempt, a token from an earlier sign-in does not fit a new one. That value is the nonce: the collage app puts a fresh random string in its request, and the photo service copies it into the ID token. In the authorization code flow, sending one is optional, but once the collage app has sent it, a token without exactly that value is refused.

The token can also say when Ava authenticated, in a claim called auth_time, so the collage app can tell a sign-in from this morning apart from one last spring. That is a different time from iat, the moment the token was issued, which can be long after she last proved who she is. A provider must include auth_time when the client asks for a recent sign-in.

OIDC also standardizes the surroundings: names for common profile information such as a name and email address, called claims; a UserInfo endpoint where a client can ask for them with an access token; a discovery document that tells a client where to find a provider's endpoints and keys; and ways to coordinate signing out. A client that understands these can work with any provider that follows the specification, rather than learning a new /me endpoint each time.

The access token keeps its job. If the collage app also wants to read Ava's photos, it can ask for both in the same request, and it will receive an ID token for signing her in and an access token for the photo API. Signing in alone does not give the collage app her photos.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The collage app's backend receives an access token from a phone app, calls the photo API's /me endpoint, and gets user-2048, Ava's account. Why is signing Ava in unsafe? 1 of 2

Choose one answer.

What does adding openid to the scope of the collage app's request change? 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