Handling unmet authentication requirements
A step-upAsking someone who is already signed in for stronger evidence before a sensitive action, such as requiring a passkey to export payroll after a password sign-in. challenge does not always end with 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. and a deleted photo. Ava might have no passkey, or cancel; a server might be unable to provide the sign-in an 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. asks for; and a successful step-up stops being fresh after a few minutes. Each case needs an ending that leaves her photos either deleted with the evidence the photo service asked for, or not deleted, and leaves her knowing which.
When the requirement cannot be met
The challenge in When an API needs stronger authentication ended well because Ava had a passkey and used it. All domains and values in these examples are fictional. Suppose instead that she has no passkey. The photo service asks for one, and she has nothing to offer except her password and authenticatorSomething 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. The server could sign her in with those two factors and issue a 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. marked two-factor, but the photo API has already said it will not accept that. The step-up specification recommends that the server fail the request instead, with the error unmet_authentication_requirements. It comes from a short OpenID Foundation companion 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., written for an authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. that cannot authenticate someone in the way the client asked, and Requesting stronger authentication meets it again in OpenID Connect:
https://editor.example/oauth/callback
?error=unmet_authentication_requirements
&state=demo-attempt-31
&iss=https%3A%2F%2Fauth.photos.exampleIf Ava had cancelled instead, the response would carry access_denied. Either way, the editor validates state and iss as it would for any response, then tells her what happened in plain terms: the photos were not deleted, deleting photos needs a recent sign-in with a passkey, and she can add a passkey in her photo account settings and try again or keep the photos. The editor cannot change the requirement, and it should not hint at ways around it.
A requirement can be impossible for some people to meet, and the specification leaves those policy choices to each deployment. If the photo service made deletion depend on passkeys without giving people a way to add one, every deletion would fail. The Authentication policy and SSO lesson described the same problem when Lab Photos required passkeys for its staff before giving them a way to enroll one. The fix belongs in the policy and enrollment, not in the protocolAn agreed set of rules for the messages two systems exchange and what each message means. HTTP, OAuth 2.0, OpenID Connect and SAML are all protocols..
Avoiding loops
Picture a server that ignores acr_values and issues another two-factor token. The API challenges, the editor sends Ava to sign in, the server issues another two-factor token, and the API challenges again. She would keep signing in and nothing would change. That loop is why the specification asks the server to fail the request rather than issue a token that does not meet the requirement.
Requirement met
- Response
- code
- New token acr
- passkey
- Photos
- Deleted
API accepts the retry
Server cannot meet it
- Response
- unmet_authentication_requirements
- New token acr
- No token issued
- Photos
- Kept, and Ava is told why
A clear ending
acr_values dropped
- Response
- code
- New token acr
- two-factor
- Photos
- Challenged again
A loop of sign-ins
A cancelled sign-in ends like the second case, with access_denied.
The editor protects against loops on its side too:
- It starts a step-up only from something Ava chose to do, such as deleting photos. A background request, such as loading thumbnails, never sends her to a sign-in page.
- It makes one step-up attempt for each action. If the API challenges the new token as well, the editor stops and explains instead of redirecting again.
- It does not refresh to satisfy a challenge. A refreshed token keeps the
auth_timeandacrof the original sign-in, so it would fail the same check. - Before sending Ava anywhere, it can check that the requested values appear in the server's
acr_values_supportedmetadata. A requirement the server does not support cannot be met by trying.
Keeping separate tokens
After a successful step-up, the editor holds two kinds of token: the everyday one from yesterday's two-factor sign-in, and the stepped-up one from this morning's passkey. The stepped-up token meets the deletion policy only for five minutes. After that it is no better for deleting than the everyday one.
The specification notes that a client may do better by keeping both and choosing the right one for each request, rather than replacing the old token with the new. Using the stepped-up token for everything gains nothing once it is stale, and a server that issues stepped-up tokens with short lifetimes would otherwise interrupt everyday browsing with frequent prompts. The editor uses the everyday token for reading and the stepped-up token for deleting, and it starts a new step-up if a later deletion is challenged.
The editor chooses between them by remembering why it obtained each token, not by reading the acr inside it. The token is opaque to the client, and the photo service could change its format at any time.
The step-up request can also ask for less. If it requested only photos.delete, the token from the passkey sign-in would carry only the access that needed it, while reading stayed with the everyday token.
The API's checks
On the photo API's side, the deletion policy becomes a short check that runs after the token has been validated and its scope confirmed:
const deletePolicy = {
acr: ['urn:photos:acr:passkey'],
maxAge: 300,
};
// Returns null when the sign-in is good enough, or a challenge to send back.
function checkSignIn(claims: AccessTokenClaims, now: number): string | null {
const strongEnough = typeof claims.acr === 'string'
&& deletePolicy.acr.includes(claims.acr);
const recentEnough = typeof claims.auth_time === 'number'
&& now - claims.auth_time <= deletePolicy.maxAge;
if (strongEnough && recentEnough) return null;
return 'Bearer error="insufficient_user_authentication", '
+ `acr_values="${deletePolicy.acr.join(' ')}", max_age="${deletePolicy.maxAge}"`;
}A missing claim counts as not meeting the requirement. The acr value is compared exactly with the accepted list, and the challenge is built only from the API's own policy, never from anything in the request. A real implementation would also allow a few seconds of tolerance for clock differences, as it does for exp.
The order matters. The specification allows an API to return a challenge before validating the token, but then anyone can learn the requirements without holding a valid token. The requirements themselves can say more than intended: an API that demands a stronger sign-in only for some accounts tells an observer which accounts are worth targeting with phishingTricking someone, usually with a message and a look-alike sign-in page, into handing over the evidence that opens their account, such as a password or a one-time code..
A challenge is a request for a better token, not a source of authority. The API never relaxes its rule because a client says Ava signed in again; only the token counts. In the other direction, a challenge can make a client send her to a sign-in prompt, so a malicious API could use challenges to interrupt her with prompts, or to make unexpected prompts seem normal. The editor follows challenges only from the photo API it was built to call, and the prompt itself appears at the photo service, where Ava can see what she is being asked to do.
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
- End every step-up attempt cleanly, with photos deleted or clearly keptBuild a delete action that steps up at most once, never refreshes to satisfy a challenge, keeps everyday and stepped-up tokens apart, and tells Ava plainly when photos were not deleted.