Beta

Create a tenant

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

When an API needs stronger authentication

Deleting photos cannot be undone, so the photo API wants each deletion to come from someone who signed in recently, with a method a phishing page cannot capture. Only the API sees what a request does, so the step-up challenge lets it tell the client that a token's sign-in is not enough, and the client fetch a new token whose sign-in is.

A request that needs more

The photo editor at editor.example, a browser application registered as the public client photo-editor, has a tidy-up tool. It finds blurry shots and duplicates and, when Ava agrees, deletes them from her library. Ava connected the editor with photos.read and photos.delete. She last signed in to the photo service yesterday morning, with her password and a code from her authenticator app, and the editor has kept the connection working with its refresh token ever since. A copied token, or a laptop left open with yesterday's session, should not be enough to empty an album.

The Authentication policy and SSO lesson described two ways a service responds to a sensitive action: reauthentication, which asks for a fresh check, and step-up authentication, which asks for stronger evidence than the person gave earlier. The photo service needs both here, because a recent sign-in alone proves little when a relay can steal a fresh session, as Limiting what stolen access can do showed. The difference in OAuth is where the question comes up.

The deletion arrives at the photo API as an ordinary request with an access token. Only the API sees that this request deletes photos, and it may weigh more than the operation itself: how many photos, how quickly, from which kind of client. The authorization server authenticated Ava yesterday and has been issuing tokens since, without knowing what any of them would be used for.

The simple alternatives cost too much. Requiring a passkey at every sign-in, or making every token last a few minutes, would make each ordinary visit harder in order to protect a rare one. What the API needs is narrower: a way to learn from the token how and when Ava authenticated, and a way to tell the client that this request needs more.

What a token can say about sign-in

The Authentication policy and SSO lesson met the two claims that carry this information, auth_time and acr, in OpenID Connect, whose lessons explain them in full, starting with Session age and reauthentication and Authentication context and methods. The JWT access token profile lets an access token carry them too, describing the sign-in behind the authorization.

In an access token they mean what they mean in an ID token. auth_time records when the person last actively authenticated at the authorization server, not when the token was issued. acr names the kind of authentication that took place, using values the authorization server and the API have agreed on. The photo service uses the two classes it already publishes for OpenID Connect sign-in:

The two acr values the photo service and its API have agreed on
ValueMeaning at the photo service
urn:photos:acr:two-factorTwo different kinds of factor, such as a password and a code from an enrolled authenticator app.
urn:photos:acr:passkeyA passkey or security key with user verification, a method a phishing page cannot capture.

There is no universal ladder of acr values. "Stronger" means only what the parties have agreed, and the word "step-up" is a metaphor for moving from a level the API will not accept to one it will.

All domains, identifiers, codes, and tokens in these examples are fictional. Decoded, the editor's current access token reads:

{
  "iss": "https://auth.photos.example",
  "sub": "user-2048",
  "aud": "https://api.photos.example",
  "client_id": "photo-editor",
  "scope": "photos.read photos.delete",
  "iat": 1790845200,
  "exp": 1790845800,
  "jti": "demo-token-id-31",
  "auth_time": 1790758800,
  "acr": "urn:photos:acr:two-factor"
}

The token was issued at 09:00 UTC today, when the editor last refreshed, but auth_time is 09:00 yesterday. Tokens obtained by refreshing carry the same auth_time and acr as the sign-in behind the authorization, because no new authentication happened. An API that relies on introspection can receive the same two values in the introspection response.

These claims are for the API. As the Using access tokens lesson explained, the editor treats the token as opaque and does not read them.

Letting the API ask

The OAuth 2.0 Step Up Authentication Challenge Protocol, published as RFC 9470 in September 2023, gives the API a standard way to say that a token's authentication is not enough. The exchange has four steps:

  1. The API refuses the request with the error insufficient_user_authentication and states what it requires: acceptable acr values, a maximum age for the sign-in, or both.
  2. The client sends the person back to the authorization server with a new authorization request carrying those requirements.
  3. The authorization server authenticates them as required and issues a new access token whose acr and auth_time describe that sign-in.
  4. The client repeats the original request with the new token, and the API checks again.

Requesting stronger authentication showed an application deciding for itself to send someone back for a stronger sign-in. Here the API makes that decision, and the client only passes it on. An authorization server that already implements OpenID Connect can take part with little or no change, and it advertises support by listing acr_values_supported in its metadata.

Step-up changes what the API knows, not what the editor knows. The editor still receives an access token, not a statement about who Ava is, and the specification is explicit that this mechanism does not turn OAuth into a sign-in protocol. The API's other checks stay in place as well. A fresh passkey sign-in does not let the editor delete photos in an album that is not hers.

Receiving the challenge

At 09:02 UTC Ava opens the tidy-up view and chooses Delete 38 photos. The editor starts with the first photo on the list and sends the deletion with the token it obtained this morning:

DELETE /photos/9137 HTTP/1.1
Host: api.photos.example
Authorization: Bearer demo-access-token-31

The photo API validates the token as usual, with the checks from Token formats and validation. Its signature, issuer, audience, and expiry are fine, and it carries photos.delete. Then the API applies its policy for deletions: acr must be urn:photos:acr:passkey, and auth_time must be no more than 300 seconds ago. The token says two-factor, and its sign-in happened 86,520 seconds ago. The API refuses:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error="insufficient_user_authentication",
  error_description="A recent passkey sign-in is required",
  acr_values="urn:photos:acr:passkey",
  max_age="300"

The header is split across lines for display. error names the problem: the authentication behind this token does not meet the API's requirements. acr_values lists the acceptable authentication context classes, separated by spaces and in order of preference, and the API will accept any one of them. max_age is the number of seconds allowed since the person's last active authentication: the last time they responded to a sign-in prompt at the authorization server. A session that quietly continues does not count. A challenge can carry either requirement or both, and if the token also lacked a scope, it could include a scope attribute as well. Some APIs name only one missing requirement in each challenge, so a client that meets the first may be challenged again for the second.

The response uses status 401, as an invalid token would, because the remedy is a different token. The error_description is optional text meant for developers. As with other error descriptions, the editor does not insert it into its page as markup.

Asking for a new sign-in

The editor remembers what it was doing, the 38 photos waiting to be deleted, and tells Ava that deleting photos needs a fresh sign-in with her passkey. When she chooses to continue, it builds a new authorization request, copying the two requirements from the challenge exactly as it received them:

https://auth.photos.example/authorize
  ?response_type=code
  &client_id=photo-editor
  &redirect_uri=https%3A%2F%2Feditor.example%2Foauth%2Fcallback
  &scope=photos.read%20photos.delete
  &acr_values=urn%3Aphotos%3Aacr%3Apasskey
  &max_age=300
  &state=demo-attempt-31
  &code_challenge=gmBRnRQIy0EQKWg3CemaN64l-xOox_nHZAphyPcG6hI
  &code_challenge_method=S256

Everything else is an ordinary authorization request, with a fresh state and PKCE challenge for this attempt. The requirements are the only new part, and they travel in two OpenID Connect parameters that mean exactly what they mean there: max_age, from Session age and reauthentication, and acr_values, from Authentication context and methods.

At the photo service, Ava still has yesterday's session. On an ordinary visit, the server would recognize her and continue without a prompt. Yesterday's sign-in is far older than 300 seconds, so the server asks her to authenticate again, and it prompts for her passkey because that is the kind of sign-in acr_values names, much as Requesting stronger authentication described. Ava uses her passkey at 09:03:00.

Under the step-up specification, the authorization server should treat the requested acr as a requirement, not a preference. It puts that value in the new access token only when the sign-in actually met it. If the sign-in falls short, the request fails instead of producing a token the API would refuse.

Ava's browser returns to https://editor.example/oauth/callback with a code, the attempt's state, and the iss parameter. The editor checks them as it would for any callback, then exchanges the code with its PKCE verifier. It is a public client, so it sends its client ID and no client credential.

Retrying with the new token

The new access token, decoded, describes this morning's passkey sign-in:

{
  "iss": "https://auth.photos.example",
  "sub": "user-2048",
  "aud": "https://api.photos.example",
  "client_id": "photo-editor",
  "scope": "photos.read photos.delete",
  "iat": 1790845385,
  "exp": 1790845985,
  "jti": "demo-token-id-32",
  "auth_time": 1790845380,
  "acr": "urn:photos:acr:passkey"
}

auth_time is 09:03:00, and the token was issued five seconds later. The editor does not decode the token to confirm any of this. It repeats the request it was trying to make and lets the API decide:

DELETE /photos/9137 HTTP/1.1
Host: api.photos.example
Authorization: Bearer demo-access-token-32
HTTP/1.1 204 No Content

The API runs the same checks as before. At 09:03:10, the sign-in is 10 seconds old, well inside the 300 allowed, and its acr is one the API accepts. The photo is deleted, and the editor continues with the other 37.

The API states its requirement, the authorization server meets it with a new sign-in, and the editor retries with the new token. The API makes the final decision both times.

The new sign-in will not stay fresh. At 09:08:00 it turns five minutes old, and from then on this token no longer meets the deletion policy, although it still works for browsing until it expires. If the tidy-up were still running then, the API would challenge again, and the editor would have to decide whether to ask Ava for another sign-in or stop.

Check your understanding

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

The editor's access token was issued at 09:00 today by refreshing, and its auth_time is 09:00 yesterday. What does auth_time describe? 1 of 3

Choose one answer.

The photo API answers 401 with error="insufficient_user_authentication" and max_age="300". What should the editor do? 2 of 3

Choose one answer.

Ava still has yesterday's two-factor session at the photo service when the editor sends her there with acr_values naming the passkey class and max_age=300. What should the server do? 3 of 3

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