How to enforce recent authentication in backend service

I have a requirement that certain sensitive operations performed by my backend services require recent interactive authentication. The backend services only have access to access tokens, not ID tokens. When the max_age parameter is provided, Auth0 provides the auth_time claim in the ID token, but not the access token. Therefore, the backend services have no way of checking whether the operation should be permitted or not.

Is there a way to get Auth0 to put the auth_time claim in the access token without being on the Enterprise tier? A post-login action cannot copy it from the ID token into the access token because the ID token is not available to the script. The event.session.authenticated_at field is marked Enterprise-only, and I’m not on the Enterprise tier, and the documentation doesn’t explicitly state that it is equivalent to auth_time anyway.

Any help would be very much appreciated.

Hi @bill.poole

You are asking whether Auth0 can place an auth_time claim in the access token for a non-Enterprise tenant, so that backend services can confirm that a user authenticated interactively within a required window before performing sensitive operations.

Summary: The auth_time claim is documented only in the ID token, and the access token does not receive it by default, so the practical options are a post-login Action that writes a verified authentication timestamp into the access token, or a backend design that relies on the ID token during the step-up.

Root Cause: When a request includes max_age, Auth0 adds auth_time to the ID token only. Access tokens for your Management API or custom API audience do not carry that claim by default, and a post-login Action cannot read the ID token, so it cannot copy the value from there.

Solution: Store the interactive login time at the moment of login, then expose it as a custom claim in the access token.

  1. Create a post-login Action that runs only when the login is interactive. Use the event.authentication details and the max_age request parameter to determine whether the user completed a fresh sign-in in this transaction, rather than a silent renewal.
  2. Write the current time in seconds to the user's app_metadata only for an interactive login, for example with api.user.setAppMetadata('last_interactive_auth', Math.floor(Date.now() / 1000)).
  3. Add that value as a namespaced custom claim to the access token, for example api.accessToken.setCustomClaim('https://yourapp.com/last_interactive_auth', timestamp). Use a namespace you own, because non-namespaced claims are rejected.
  4. Check the claim in your backend before each sensitive operation. Compare the stored timestamp with the current time, and reject the request when the difference exceeds your allowed window.
  5. Verify the behavior after a refresh-token exchange. Confirm that the claim survives the refresh and that a silent renewal does not overwrite the timestamp, because the access token issued during a refresh is produced without an interactive login.

We hope this helps you implement the recent-authentication check for your sensitive operations.

Kind Regards,
Nik