Session age and reauthentication
A 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. can be busy and 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. brand new while the sign-in behind them is a day old. Before a sensitive change, a 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. asks the provider for a recent sign-in with max_age, then checks auth_time itself, because the request passed through the browser on its way.
When a recent sign-in matters
All domains, identifiers and tokens in these examples are fictional.
At 15:00 UTC on 2 October, Ava decides her next poster order should go to her office instead of her home, and she opens the collage app's delivery address page. She has been signed in to the collage app since its silent check at 08:00, coming back to her collages every hour or so, often enough that its two-hour idle timeout never ran out. To the collage app, nothing about this visit looks unusual.
The delivery address decides where a parcel of Ava's photos goes. Someone who sat down at her unlocked computer, or who had copied her collage app session cookieA small value that a website asks the browser to store and send back with later matching requests. Cookies commonly carry a session identifier, so the site can recognize an ongoing sign-in without your password., could send the order to themselves in a few clicks. Deleting her collage app account is similar, and it can't be undone. For actions like these, the collage app wants more than a valid session. It wants evidence that the person who can sign in to Ava's photo account did so recently, which Authentication policy and SSO called fresh authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do..
Ava's busy morning doesn't count as that evidence. Each time she opened a collage, the collage app moved its idle deadline forward without asking her for anything. The silent check at 08:00 produced a new 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., but the photo service issued it from the session it already had. Staying active keeps a session alive, and a new token can describe an old sign-in. Neither one is a new authentication.
So the collage app sets a rule of its own: changing the delivery address needs a sign-in from the last five minutes. To apply it, it keeps 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., subject and authentication time from the validated ID token in Ava's session record. The rule sits beside the collage app's ordinary permission check rather than replacing it. A fresh sign-in shows that Ava is present; it doesn't let her account change an order that belongs to someone else.
Her session record shows how far away that is:
| Session field | Value |
|---|---|
| Account | 8812 |
| Signed in with | https://auth.photos.example, subject user-2048 |
| Session created | 08:00:00 UTC on 2 October |
auth_time | 1790845185, which is 08:59:45 UTC on 1 October |
The session is seven hours old, but the sign-in behind it is more than thirty hours old. The silent check this morning created a new collage app session without a new authentication, and the collage app recorded the original auth_time, as it should. Nothing since then has moved that time forward, and nothing the collage app does on its own, such as refreshing its access to Ava's photos, ever could.
Requesting a fresh sign-in
The collage app keeps Ava's new office address on its server as a pending change, and starts a new sign-in attempt for it, with a fresh 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. and 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, an expiry, and a note of the five-minute rule the result must meet. Then it sends her browser to the photo service with one parameter this course hasn't used yet, max_age=300:
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-signin-6
&nonce=demo-nonce-6
&code_challenge=zIg1QZV-I3GegEGQK73TUZpKR-4vRsAH1XMK4FTxM7Q
&code_challenge_method=S256
&max_age=300
&id_token_hint=eyJhbGciOiJSUzI1NiIsImtpZCI6InBob3Rvcy1ycy0yMDI2LTA5IiwidHlwIjoiSldUIn0...The ID token hint, Ava's earlier ID token from Login hints, is shortened here. It asks the photo service to answer only for the account this session belongs to. The scope is only openid, because the collage app needs a sign-in, not another copy of Ava's profile.
max_age is the oldest sign-in the collage app will accept, in seconds. If the photo service authenticated Ava within the last five minutes, it may answer without showing a page. Otherwise it asks her to authenticate again. Either way, a request with max_age requires auth_time in the returned ID token, so the collage app can see what actually happened.
The photo service sees that Ava's last sign-in was thirty hours ago and asks for her password. She enters it at 15:00:20, and the collage app receives a new ID token:
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "photo-collage",
"iat": 1790953225,
"exp": 1790953525,
"auth_time": 1790953220,
"nonce": "demo-nonce-6"
}Had Ava signed in to the photo service two minutes earlier for some other reason, the same request would have come back without a page, and auth_time would show those two minutes. That is what a maximum age offers over a demand for a new sign-in: it asks for exactly the freshness the collage app needs and no more.
The other way to ask is prompt=login, from Prompt and account selection, which asks the photo service to authenticate Ava again however recent her session is. The specification treats max_age=0 as equivalent. The difference lies in what comes back. Any request with max_age, including max_age=0, must receive auth_time. A request with only prompt=login isn't guaranteed to, and without it the collage app can't tell whether a new sign-in took place.
A client can also make sure auth_time arrives without asking for a new sign-in, by requesting it as an essential claim or by registering with require_auth_time so that every ID token carries it. Its registration can set default_max_age too, which applies whenever a request leaves max_age out, and which a request's own value overrides. None of these settings replaces the collage app's check of what comes back.
Checking auth_time
Asking isn't enough, because the request passed through Ava's browser. Somebody using it could remove max_age before the request reached the photo service and receive a perfectly valid token describing yesterday's sign-in. So when the response comes back, the collage app matches it to the pending attempt, uses that attempt only once, exchanges the code with the stored verifier, and validates the ID token as usual, including the nonce demo-nonce-6. Then it adds checks of its own:
claims = validate_id_token(response, pending) # signature, issuer, audience, times, nonce
if (claims.iss, claims.sub) != (session.iss, session.sub):
reject() # someone else signed in
if claims.auth_time is None:
reject() # max_age was sent, so it must be present
if now() - claims.auth_time > pending.max_age + CLOCK_TOLERANCE:
reject() # not recent enough
if claims.auth_time > now() + CLOCK_TOLERANCE:
reject() # implausibly in the future
if not current_permission(session.user, pending.change):
reject() # fresh authentication cannot grant permission
session.auth_time = claims.auth_time
apply(pending.change)A missing auth_time is a failure, not a pass, because the photo service was required to include it. The age check allows a small tolerance for differences between the two servers' clocks, measured in seconds, never enough to turn five minutes into an hour. Notice which claim it reads: iat only says when the token was issued, which is always moments ago, so it can't tell a new sign-in from an old one.
Ava entered her password
- sub
- user-2048
- iat
- 15:00:25
- auth_time
- 15:00:20
- Signed in
- 5 seconds ago
Apply the change
Yesterday's sign-in reused
- sub
- user-2048
- iat
- 15:00:25
- auth_time
- 08:59:45, 1 October
- Signed in
- More than 30 hours ago
The address stays as it was
A different account signed in
- sub
- Another subject
- iat
- 15:00:25
- auth_time
- 15:00:18
- Signed in
- 7 seconds ago
Discard the pending change
iat only says when the token was issued.
At 15:00:25 the new token's auth_time is five seconds old, well inside the limit. When every check passes, the collage app records the new auth_time in Ava's session and applies the pending change, once. The checks live in the server code that changes the address, not in the page that shows the form, so a request sent straight to that code meets the same rule.
Any failed check leaves the address as it was. If someone else signed in at the photo service, their sign-in says nothing about Ava, however valid it is. The collage app discards the pending change, and it may end her session too, since it can no longer be sure who is at the keyboard. If Ava cancels at the photo service, or can't sign in, the collage app receives an error instead of a code. Her session continues, and the collage app can explain that the change needs a recent sign-in and offer to try again.
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
- Demand a recent sign-in with max_age and check auth_time yourselfSee an old sign-in behind a new token, request a fresh sign-in with max_age and a hint, and reject stale or different identities in the relying party before a sensitive change.