- Track guest users across page loads and sessions
- Store metadata such as shopping cart references, preferences, consents, and profiling information
- Issue access tokens for API calls without requiring authentication
- Transfer anonymous activity to authenticated accounts when users sign up or log in
How it works
Gather anonymous sessions data
When you decide to start gathering information about a user, even one who has not authenticated yet, your application sends aPOST request to the /anonymous/token endpoint.
Auth0 responds with two tokens:
- A session token that identifies and persists the anonymous session.
- An access token that the user can present to your resource servers (APIs).
user_id, so all activity is traceable to a single origin.
Using the access token, anonymous users can call any of your existing APIs.
Anonymous session data of user anon@1234-5678-90
Transfer anonymous sessions data to user’s metadata
There are different mechanisms to transfer an anonymous session into an authenticated user, depending on the flow you are using and where your application resides in terms of domains and FQDNs.Transferring a session in redirect flows (authorization code, authorization code with PKCE)
Transferring a session through a cookie
When a user who has an anonymous session decides to log in or sign up, your application passes theanonymous_session_token to the /authorize endpoint using a cookie. This mechanism works when your application and the authorization server live in the same domain — for example, when your application lives in application.mydomain.com and the authorization server’s custom domain is auth.mydomain.com. In this case, the cookie is considered same-domain and forwarded to the authorization server automatically, so logging in works as usual:
cookie example
Transferring a session through a transfer ticket
In scenarios where cookies would need to travel cross-domain, multiple browser mechanisms will block the anonymous session cookie from being sent over the network. Even with the correct CORS configuration on the server and client, advanced mechanisms such as Apple’s Intelligent Tracking Protection (ITP) may block or drop the cookie, resulting in unmatched users. To overcome this, use a two-step anonymous session transfer mechanism that does not rely on cookies:- Call the
/anonymous/tokenendpoint, requesting theurn:auth0:anon_transfer_tokenaudience, to receive ananon_transfer_tokenin exchange. - Include the
anon_transfer_tokenas a parameter in the/authorizecall.
anon_transfer_token is bound to the IP address that requested it. If you plan to use this cookieless mechanism for login, Auth0 recommends turning off the issuance of anonymous session cookies in your tenant settings to avoid undesired clashes or injections.
Upon successful login, Auth0 makes the anonymous session data available in your pre-user-registration and post-login Actions triggers using the event.anonymous_session object.
anonymous session object
Transferring a session in a Resource Owner Password Grant (ROPG) scenario
When using ROPG for login, include theanonymous_session_token in the request body of the /oauth/token call:
Anonymous session token in a ROPG request
End the anonymous session after transfer
Anonymous session cookies are not automatically flushed when a user authenticates, so the cookie can continue to be sent in subsequent logins. To end the session, use the/anonymous/logout endpoint:
Best practices
Here are some best practices for anonymous sessions:- Configure appropriate anonymous session lifetimes to avoid losing a user’s anonymous session data; Auth0 recommends a lifetime of 30 days or longer.
- Select anonymous session’s JSON Web Encryption (JWE) encryption to ensure that potential attackers cannot see the contents of the session.
-
Restrict what anonymous
anon@users can do in your API. - Validate tokens and sanitize metadata, never trust metadata or tokens from clients without server-side validation.
- Cache access tokens since they can be reused until they expire.
- Batch and minimize metadata updates. Avoid frequent metadata updates.
Limitations
- Password reset flows are not supported by anonymous sessions.
- Device Code is not supported because the authentication request and the actual login happen on different devices.
- Client-Initiated Backchannel Authentication (CIBA) is not supported because the authentication request and confirmation happen on different devices.
- Custom token exchange is not supported due to the nature of the transactions (for example, impersonation), which creates a likelihood of attributing anonymous data to the wrong user.
- Refresh token exchange is not supported by anonymous sessions because the user is already logged in if they had a refresh token.
Learn more
- Configure Anonymous Sessions Learn how to configure anonymous sessions.
- Configure Custom Claims for Anonymous Sessions Learn how to map anonymous session metadata into access token claims.
- Anonymous Sessions Use Cases Learn about anonymous sessions use cases.