From delegated access to sign-in
The 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. 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.
Why an access token is not a sign-in
Here is the shortcut. The collage app runs the authorization codeA short-lived, single-use value that the authorization server sends back to a client through the browser. The client swaps it for tokens in a direct request to the authorization server; APIs never accept it. flow, receives an access token, and calls an endpoint on the photo APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. 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.
/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 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. 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, 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. 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 JWTA JSON Web Token: a compact token made of Base64url-encoded parts that carries claims and is usually signed. Anyone holding it can decode and read the claims, so the signature shows who issued it but hides nothing. 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 endpointAn OpenID Provider endpoint that returns claims about the signed-in person to a client presenting an access token. Its sub must match the ID token's before the client uses anything it returns. where a client can ask for them with an access token; a discovery documentA JSON document that an OpenID Provider publishes at a well-known address under its issuer, listing its endpoints, where to find its signing keys, and its supported features so clients can configure themselves from one value. 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.
Try it in the Lab
- See why an access token can't sign Ava in, and what an ID token addsHand the collage app's backend a genuine access token issued to the printer, watch UserInfo answer anyway, and read how an ID token names its client and attempt.