Prerequisites
To use anonymous sessions:- You must have an Auth0 account.
- Register your Auth0 application. If you do not have an Auth0 application, you can get started with the Auth0 React or Next.js Quickstarts.
- Register an API (resource server).
Configure anonymous sessions in your Auth0 tenant
Using the Dashboard
- Go to Tenant Settings > Advanced, and scroll down to the session settings.
- Enter a value for the Anonymous Session Lifetime, in minutes.
- Enable or disable the Anonymous Session Cookie switch to control whether anonymous session requests return the
auth0_anoncookie.
Using the Management API
To set the anonymous session lifetime and cookie behavior, make aPATCH request to the /api/v2/tenants/settings endpoint:
lifetime_in_minutessets how long a session is valid for.activate_cookiesets whether to issue theauth0_anoncookie in anonymous flows. Set this tofalseif you plan to use the cookieless transfer-ticket mechanism instead.
Enable anonymous sessions in your application
Using the Dashboard
- Go to Applications > Applications, and select the application you want to configure.
- Scroll down to the anonymous session settings.
- Enable the switch to allow this application to issue anonymous sessions.
Using the Management API
To enable anonymous sessions in your Auth0 application, make aPATCH request to the /api/v2/clients/{id} endpoint:
Enable anonymous access in your API
Using the Dashboard
- Go to Applications > APIs, and select the API you want to configure.
- Scroll to the Access token expiration section and set the Anonymous Access Token Lifetime, in seconds. The minimum is 1 day and the maximum is 30 days.
- Scroll to Application Access Policy, and set the Anonymous Access policy to Per-app authorization to enable anonymous sessions using this audience for their access tokens.
Using the Management API
To enable anonymous sessions in your API, make aPATCH request to the /api/v2/resource-servers/{id} endpoint:
token_lifetime_for_anonymous_access_tokenssets the expiration time, in seconds, of access tokens this API issues in an anonymous session context.subject_type_authorization.anonymous_usersets whether individual applications can use this API in anonymous sessions (based on policies) or whether this API disallows issuing anonymous access tokens at all.
Create an API Access policy for anonymous users
Using the Dashboard
- Go to Applications > APIs, and select the API you want to configure.
- Navigate to the Application Access tab.
- For each application you want this API to issue access tokens to in an anonymous context, select Edit.
- In the drawer that appears, navigate to the Anonymous Access tab, and select the permissions you want to grant anonymous users requesting this audience when using this application.
- Select Save.
Using the Management API
Once anonymous sessions are enabled in your API, make aPOST request to the /api/v2/client-grants endpoint:
Configure custom claims
You can configure custom claims to map anonymous session metadata directly into the access tokens issued for a specific audience. This is useful because there is no post-login Action execution in an anonymous-session context, soapi.accessToken.setCustomClaim() isn’t available to enrich anonymous access tokens the way it is for authenticated ones. For more information, read Configure Custom Claims for Anonymous Sessions.
Create an anonymous session
Once anonymous sessions are configured in your tenant, application, and API, you can create an anonymous session by making aPOST request to the /anonymous/token endpoint:
session_token and an access_token:
Next steps
- Anonymous Sessions Use Cases Learn about anonymous sessions use cases.