Hi @ptidwell
Welcome back to the Auth0 Community!
You want to verify your understanding of how Auth0 session idle timeout works. You are using api.session.setIdleExpiresAt() to set a 15-minute session idle timeout, but your access token has a 1-hour lifespan. This creates a mismatch: users can continue using the application with a valid access token, but their Auth0 session expires after 15 minutes of inactivity, causing them to be logged out unexpectedly when they request a new token.
Auth0 recommends setting your access token lifetime to 10 minutes when using a 15-minute session idle timeout. This ensures active users trigger token refresh before the session expires. Short-lived access tokens (below 30 minutes) are standard practice, and the increased traffic from more frequent token refreshes is negligible.
Root Cause:
Session idle timeout and access token expiration are independent mechanisms:
- Session Idle Timeout β Tracks inactivity at the Auth0 Authorization Server level. The session expires if the user does not interact with Auth0's
/authorize endpoint within the specified time (15 minutes in your case).
- Access Token Expiration β Tracks the validity of the token itself. Your application can use the token to call APIs until it expires (1 hour in your case).
The problem occurs because:
- A user can be actively using your SPA with a valid 1-hour access token
- But if they don't request a new token from Auth0 within 15 minutes, their Auth0 session expires
- When the access token finally expires and the SPA tries to refresh it, Auth0 rejects the request because the session is no longer active
- The user is forced to log in again, even though they were actively using the application
Solution:
Step 1: Align access token lifetime with session idle timeout
Set your access token lifetime to a value shorter than your session idle timeout. Auth0 recommends:
- Session Idle Timeout: 15 minutes
- Access Token Lifetime: 10 minutes
This ensures that active users will request a new token before the session expires, automatically extending the session.
Configure in Auth0 Dashboard:
- Navigate to Applications β Your Application β Settings
- Scroll to Token Expiration (Seconds)
- Set to 600 seconds (10 minutes)
Step 2: Understand the interaction between tokens and session
When your SPA requests a new access token via getAccessTokenSilently() (or similar), it makes a request to the /authorize endpoint. This request:
- Extends the session idle timeout β The 15-minute inactivity timer resets
- Issues a new access token β Valid for 10 minutes
- Preserves user experience β The user is not prompted to log in again
Step 3: Verify your SPA is configured for token refresh
Ensure your SPA SDK is configured to refresh tokens automatically:
React SDK example:
import { Auth0Provider } from "@auth0/auth0-react";
<Auth0Provider
domain="your-tenant.auth0.com"
clientId="your-client-id"
redirectUri={window.location.origin}
useRefreshTokens={true} // Enable refresh tokens
cacheLocation="localstorage" // Persist tokens
>
<App />
</Auth0Provider>
Step 4: Verify tenant session settings
Navigate to Auth0 Dashboard β Settings β General.
Verify:
- Inactivity Timeout: 15 minutes (or your desired idle timeout)
- Require login after: Set to an appropriate value (e.g., 7 days for maximum session duration)
Step 5: Test the flow
- User logs in β Access token issued (valid 10 minutes), session created (idle timeout 15 minutes)
- User actively uses app β At ~9 minutes, SPA automatically refreshes token via
getAccessTokenSilently()
- Token refresh succeeds β New 10-minute token issued, session idle timer resets to 15 minutes
- User remains logged in β No unexpected logout
Why 10 Minutes for a 15-Minute Timeout?
The 5-minute buffer ensures:
- Token refresh happens before session expiration β Even if there's a slight delay in the refresh request, the session will still be active
- Active users never hit the idle timeout β Continuous activity keeps both the token and session fresh
- Inactive users are properly logged out β If a user stops interacting, the session expires after 15 minutes of true inactivity
Traffic Impact: Negligible
Auth0 confirms that short-lived access tokens (below 30 minutes) are standard practice. The increased traffic from more frequent token refreshes is:
- Expected by the platform β Auth0's infrastructure is designed for this pattern
- Negligible in impact β Token refresh requests are lightweight and cached by the SDK
- Worth the security and UX benefits β Short-lived tokens reduce the window of exposure if a token is compromised
Important Clarification: Refresh Tokens vs. Session Interaction
A critical distinction:
- Refresh token exchanges do NOT extend the session idle timeout β Calling
/oauth/token to exchange a refresh token for a new access token does not reset the 15-minute inactivity timer
- Only
/authorize requests extend the session β Silent authentication (via getAccessTokenSilently()) calls /authorize with prompt=none, which DOES reset the idle timeout
This is why configuring your SPA to use getAccessTokenSilently() (which calls /authorize) is essential, not just relying on refresh token exchanges.
Kind Regards,
Nik