Skip to main content

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.

How It Works

When a Back-Channel Logout event occurs:
  1. Auth0 sends a logout_token (a JWT) to your application’s /auth/backchannel-logout endpoint
  2. The SDK validates the logout_token signature and claims
  3. The SDK calls your session store’s deleteByLogoutToken method
  4. Your session store removes the user’s session based on the sid or sub claim
  5. Your application responds with 200 OK to acknowledge the logout

Prerequisites

Back-Channel Logout requires a stateful session store implementation. Cookie-based sessions alone cannot support Back-Channel Logout because there’s no way to invalidate cookies stored on the client without their participation.
You must implement a custom session store with the deleteByLogoutToken method. See the Database Sessions guide for implementation details.

Configuration

Step 1: Implement Session Store

Create a session store with deleteByLogoutToken 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:
You should receive a 400 error (missing logout_token) instead of 404, confirming the route is mounted.

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
If you customize the route path, update the Back-Channel Logout URL in your Auth0 Dashboard to match.

Session ID Handling

The sid (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 in tokenSet.sessionId after callback:

LogoutToken Structure

The LogoutToken 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-logout event
If validation fails, the SDK returns 400 Bad Request and does not call deleteByLogoutToken.

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

  1. Create a session by logging in
  2. Trigger logout from another application using the same Auth0 tenant
  3. Verify session deleted by checking your session store
  4. 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:
  1. Missing sessionId mapping: Auth0 session ID not stored
  2. Incorrect implementation: deleteByLogoutToken not implemented correctly
  3. Database connectivity: Connection to session store failing
Solutions:
  • Verify sessionId is stored during session creation
  • Add logging to deleteByLogoutToken to debug
  • Check database connectivity and permissions

Auth0 Not Sending Logout Tokens

Possible causes:
  1. URL not configured: Back-Channel Logout URL not set in Auth0 Dashboard
  2. URL unreachable: Endpoint not accessible from Auth0
  3. Feature not enabled: Back-Channel Logout not enabled in tenant settings
Solutions:
  • Verify URL is configured correctly in Auth0 Dashboard
  • Test endpoint accessibility with curl
  • Ensure Back-Channel Logout is enabled in tenant settings

Best Practices

  1. Implement logging: Log all Back-Channel Logout events for audit trail
  2. Monitor errors: Track failed logout attempts and investigate causes
  3. Use indexes: Index sub and sessionId columns for efficient deletion
  4. Cleanup expired sessions: Implement periodic cleanup of expired sessions
  5. Test thoroughly: Test with multiple sessions and edge cases

Further Reading