Requesting stronger authentication
Some actions need a stronger or more recent sign-in than the 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. already holds. This lesson follows the collage app as it sends Ava back to the photo service for a passkeyA credential that your phone, computer or password manager creates for one website and keeps for you, unlocked with a fingerprint, face or PIN. Nothing you could type is sent, and it works only for the site it was made for, which helps it resist phishing. before a sensitive download, checks what comes back against its own rule, and handles a provider that cannot comply.
A download that needs more
Ava and two friends are building a poster in the collage app from photos of their autumn trip. The board for it holds the full-resolution originals, straight from the photo service, and anyone who downloads them gets every photo at full size. At 10:15 UTC on 3 October, Ava opens the board and selects Download originals. She has been signed in since 08:30, when she used her password and an authenticator appSomething a person controls and uses to prove control of an account, such as a memorized password, an app that generates one-time codes, or a security key. It counts only after it has been registered to that account. code at the photo service. All domains, identifiers and tokens in these examples are fictional.
Before the collage app looks at how Ava signed in, it checks whether she may have the originals at all. She is a member of the autumn board, and members may download. Had she not been, the collage app would refuse the download there and then. Sending someone off for a stronger sign-in can't add them to a board.
With permission settled, the collage app turns to the sign-in behind the session. Its rule for downloading originals has two parts. The sign-in must meet the photo service's class urn:photos:acr:passkey, which the photo service defines as a passkey or security keyA small physical device, plugged in or held near a phone or computer, that holds credentials and uses them to prove you have it. It is an authenticator that resists phishing. unlocked with a PIN or fingerprint, and it must be no more than fifteen minutes old. A password and an app code can both be typed into a convincing fake page and relayed to the real one, while a passkey's response is tied to the site that asked for it, as What makes authentication multi-factor explained. The classes and the acr claim that reports them come from Authentication context and methods. Ava's session falls short on both parts:
| Session field | Recorded | Required for originals |
|---|---|---|
acr | urn:photos:acr:two-factor | urn:photos:acr:passkey |
auth_time | 1791016200, which is 08:30:00 UTC | No more than 900 seconds old |
This is step-up authentication: asking for stronger or fresher authentication at the moment an action needs it, rather than demanding the strongest sign-in for everything. Authentication policy and SSO introduced the idea. Here the collage app makes the decision, because the download happens in the collage app, and the photo service performs the stronger sign-in.
So the collage app sets the download aside rather than refusing it. It saves the pending download on its server, with the board, the photos and the rule they need, and starts a new sign-in attempt with its own state, 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., 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 expiry, as it would for any sign-in. Keeping the download on the server matters later. When Ava comes back, the collage app resumes the download it saved, instead of following a destination carried in the response, which anyone could have edited on the way.
Sending the person back
The request the collage app builds carries both parts of the rule:
https://auth.photos.example/authorize
?response_type=code
&client_id=photo-collage
&redirect_uri=https%3A%2F%2Fcollage.example%2Fsignin%2Fcallback
&scope=openid
&state=demo-collage-2
&nonce=demo-collage-nonce-2
&code_challenge=T0sO5nn95rTe6T6C4-oxfW6yhwJ-cQcpMGwYz4x9IWI
&code_challenge_method=S256
&max_age=900
&claims=%7B%22id_token%22%3A%7B%22acr%22%3A%7B%22essential%22%3Atrue%2C%22values%22%3A%5B%22urn%3Aphotos%3Aacr%3Apasskey%22%5D%7D%7D%7D
&id_token_hint=eyJhbGciOiJSUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2IiwidHlwIjoiSldUIn0...Each part has one job. The claims parameter asks for an essential acr claim with the accepted class, which names the required context. max_age=900 asks for a sign-in no more than fifteen minutes old, as in Session age and reauthentication. The earlier validated 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. goes in id_token_hint, which tells the photo service whose sign-in this must be, as in Login hints.
How to meet the request is up to the photo service. Had Ava signed in five minutes ago, it could have asked only for what was missing, the passkey. The 08:30 sign-in is far older than fifteen minutes, so it needs a fresh authentication, and Ava's passkey unlocked with her fingerprint supplies one that meets the class as well. Whatever the photo service asks for, the collage app gets one of two answers back: a code for a sign-in that meets the requirement, or an error saying it could not be met. Ava uses her passkey, and this ID 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. comes back:
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "photo-collage",
"iat": 1791022520,
"exp": 1791022820,
"auth_time": 1791022515,
"nonce": "demo-collage-nonce-2",
"acr": "urn:photos:acr:passkey",
"amr": ["pop", "mfa"]
}Before it reads any of that, the collage app checks the callback like any other: the state must belong to the pending step-up, and the 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. must be the photo service. It exchanges the code with the stored verifier and validates the ID token completely, nonce included. Only then does it compare the token with the download's rule:
- The issuer and subject match the session. A passkey belonging to someone else must not unlock Ava's download.
- The
acris on the download's list, which holds onlyurn:photos:acr:passkey. auth_timeis present, no more than 900 seconds old, and not in the future, allowing only a small clock tolerance either way.
None of these checks merely repeats the request. The request crossed the browser, where someone could have removed the claims parameter or max_age and still received a valid token for a weaker or older sign-in. Asking for an essential claim is not the same as receiving one. The amr list goes into Ava's sign-in history, but the decision rests on the agreed class and on her current permission.
All three checks pass. The collage app records the new acr, auth_time and amr in the session and gives the browser a new session identifier, because the session now carries more authority than before. Staying signed in explained the same step at sign-in. Then it resumes the pending download, checking Ava's membership of the board once more. If a friend had removed her from the board in the minute it took to find her phone, a successful step-up would not bring that access back.
A second download at 10:25 needs no new trip: the session's class is on the list, and the sign-in is ten minutes old. After 10:30:15 the fifteen minutes are up, and the next download sends Ava back again. Ordinary pages carry on throughout, because they accept either class and set no age limit.
When the provider cannot comply
Suppose Ava had never added a passkey, and has no other phishing-resistantA property of an authentication method that binds sign-in to the real service, so evidence entered on a look-alike site cannot be passed on and used. Passkeys have it; passwords and one-time codes do not. method enrolled. The photo service can't meet an essential acr request, so it treats the attempt as a failed authentication and redirects back with an error:
https://collage.example/signin/callback
?error=unmet_authentication_requirements
&state=demo-collage-2
&iss=https%3A%2F%2Fauth.photos.exampleunmet_authentication_requirements comes from a short companion specification to 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.. A provider uses it when it cannot authenticate the person in the way the 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. required, and it is the expected answer when an essential acr request can't be met. Not every provider supports it. Some report the same situation with a more general error, and a provider that doesn't honor essential claims may return a sign-in at a weaker class, which the collage app's own check then rejects. If Ava simply cancels at the passkey prompt, the answer is typically access_denied.
The collage app handles the error with the same care as a success:
- It validates the response as it would a success, matching
stateto the pending step-up and checking the issuer. There is no code, so there is nothing to exchange. - It discards the pending download and leaves the originals where they are.
- It keeps Ava's existing session. The 08:30 sign-in still meets the rules for ordinary pages, and a missing passkey says nothing against it.
- It explains what the download needs: "Downloading originals needs a passkey or security key. Add one in your photo account's security settings, then try again."
- It records the outcome: the action, the requirement, the error code, and a correlation ID for the attempt, without tokens or the request URL.
One tempting fix is to try again at once with acr_values instead. That only turns the requirement into a preference. The photo service may then complete the sign-in at the two-factor class, and the token that comes back will be valid in every other respect. The collage app's check must still refuse it for originals, so the retry gains nothing except a second trip for Ava.
A sign-in by someone else is handled at two points. Because the request carried Ava's ID token as a hint, a careful provider refuses to return anyone else's sign-in for it, and answers with an error such as login_required. If a provider ignored the hint, or the hint was stripped from the request, an ID token for another subject would come back, and the first of the collage app's checks would refuse it. Either way the collage app discards the pending download. When a token for someone else does arrive, it also ends the session: someone else's passkey was used in Ava's session, and the collage app can no longer be sure who is at the keyboard.
Here the collage app decided that the download needed more, because the download happens in the collage app. The Step-up authentication challenges lessons in Advanced OAuth, starting with When an API needs stronger authentication, follow the other case, where an API makes that decision: the requirement reaches the client in the API's error response and travels on to the authorization server in the same acr_values and max_age parameters. Wherever the requirement starts, the provider performs the stronger sign-in, and the party that set the requirement checks acr and auth_time in what comes back.
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
- Step up for a download of originals and enforce it in the relying partyAsk for Noah's passkey with an essential acr, max_age and his hint, check the result before releasing the originals, check permission again, and handle unmet_authentication_requirements without a tempting retry.