Overview
Back-Channel Logout is an OpenID Connect feature that allows Auth0 to notify your application when a user’s session is terminated. This enables you to invalidate the user’s session in your application even when the logout is initiated from a different application or by an administrator.Read more about Back-Channel Logout in the Auth0 documentation.
How It Works
When a Back-Channel Logout event occurs:- Auth0 sends a
logout_token(a JWT) to your application’s/auth/backchannel-logoutendpoint - The SDK validates the
logout_tokensignature and claims - The SDK calls your session store’s
deleteByLogoutTokenmethod - Your session store removes the user’s session based on the
sidorsubclaim - Your application responds with 200 OK to acknowledge the logout
Prerequisites
You must implement a custom session store with thedeleteByLogoutToken method. See the Database Sessions guide for implementation details.
Configuration
Step 1: Implement Session Store
Create a session store withdeleteByLogoutToken support:
lib/session-store.ts
The
LogoutToken object contains either a sid claim (session ID), a sub claim (user ID), or both. Your implementation should handle all cases appropriately.Step 2: Configure Auth0Client
Configure your Auth0 client to use the session store:lib/auth0.ts
Step 3: Verify Route is Mounted
The SDK automatically mounts the/auth/backchannel-logout route. Verify it’s accessible:
Step 4: Configure Auth0 Dashboard
In your Auth0 Dashboard:1
Enable Back-Channel Logout
Go to Applications > Your Application > Advanced Settings > OAuthEnable “Back-Channel Logout”
2
Configure Logout URL
Set the Back-Channel Logout URL to your application’s endpoint:
3
Save Changes
Save your application settings.
Custom Route Path
You can customize the Back-Channel Logout route path:lib/auth0.ts
Session ID Handling
Thesid (session ID) claim in the logout token refers to the Auth0 session ID, not your application’s session ID. Store this mapping in your database:
Storing Auth0 Session ID
The Auth0 session ID is available intokenSet.sessionId after callback:
LogoutToken Structure
TheLogoutToken object passed to deleteByLogoutToken has the following structure:
Implementation Examples
Prisma Session Store
lib/session-store.ts
Redis Session Store
lib/session-store.ts
Error Handling
The Back-Channel Logout endpoint returns appropriate HTTP status codes:Validation Errors
The SDK validates the logout token automatically:- Signature verification using Auth0’s public keys
- Issuer (
iss) must match Auth0 domain - Audience (
aud) must match client ID - Required claims must be present
- Events claim must contain
backchannel-logoutevent
Security Considerations
Token Validation
The SDK automatically validates:- JWT Signature: Verifies the token is signed by Auth0
- Issuer: Confirms the token is from your Auth0 tenant
- Audience: Ensures the token is intended for your application
- Claims: Validates required claims are present
Endpoint Security
- The endpoint should be accessible to Auth0 only
- Use HTTPS in production
- Consider IP allowlisting if possible
- Monitor for suspicious activity
Session Cleanup
Implement cleanup for expired sessions:Testing
Manual Testing
- Create a session by logging in
- Trigger logout from another application using the same Auth0 tenant
- Verify session deleted by checking your session store
- Attempt to use session to confirm it’s invalidated
Automated Testing
tests/backchannel-logout.test.ts
Monitoring
Monitor Back-Channel Logout events:lib/session-store.ts
Troubleshooting
Sessions Not Being Deleted
Possible causes:- Missing sessionId mapping: Auth0 session ID not stored
- Incorrect implementation:
deleteByLogoutTokennot implemented correctly - Database connectivity: Connection to session store failing
- Verify
sessionIdis stored during session creation - Add logging to
deleteByLogoutTokento debug - Check database connectivity and permissions
Auth0 Not Sending Logout Tokens
Possible causes:- URL not configured: Back-Channel Logout URL not set in Auth0 Dashboard
- URL unreachable: Endpoint not accessible from Auth0
- Feature not enabled: Back-Channel Logout not enabled in tenant settings
- Verify URL is configured correctly in Auth0 Dashboard
- Test endpoint accessibility with
curl - Ensure Back-Channel Logout is enabled in tenant settings
Best Practices
- Implement logging: Log all Back-Channel Logout events for audit trail
- Monitor errors: Track failed logout attempts and investigate causes
- Use indexes: Index
subandsessionIdcolumns for efficient deletion - Cleanup expired sessions: Implement periodic cleanup of expired sessions
- Test thoroughly: Test with multiple sessions and edge cases