Single sign-out (SSO logout)
Overview
Single sign-out (SSO logout) logs a user out from every application in the organization in one go. When they sign out from one app, all other apps in the same SSO setup are signed out as well.
Use it for:
- Security incidents: Immediately terminate all active sessions when a security breach is detected
- Organization-wide logout policies: Enforce logout across all services when users leave the organization or change roles
- Compliance requirements: Ensure users are completely logged out from all systems when required by regulations
- User-initiated logout: Allow users to log out from all applications with a single action
How it works
The logoutAll parameter chooses the mode:
Full SSO logout (default, logoutAll=true or omitted):
- Delete all active sessions: All active sessions for the user across all applications in the organization are terminated
- Expire all access tokens: All access tokens that were issued to the user are immediately invalidated
- Clear the current session: The user's current session and authentication state are cleared
- Send logout notifications: Notification providers receive the logout event with all session IDs and token hashes
This ensures that the user is completely logged out from all integrated applications and cannot access any resources without re-authenticating.
Session-only logout (logoutAll=false):
- Delete current session: Only the current session is terminated
- Clear current authentication state: The user's current session and token are cleared
- Send targeted notification: Notification providers receive the logout event with the current session ID and associated access token hashes
This allows users to logout from a specific device or browser while remaining logged in on other sessions. This is useful when users share accounts across multiple devices or have concurrent sessions they want to manage individually.
The access token hashes included in session-level logout notifications enable your subsystems to identify exactly which tokens need to be invalidated. When a user logs out from a specific browser or device, match the token hashes against active sessions and perform targeted invalidation without affecting other devices where the user remains logged in.
Logout notifications
On SSO logout, Casdoor sends a request to each notification provider configured for the application the user signed up with. The notifications include session IDs, access token hashes, and cryptographic signatures for secure, synchronized logout across all integrated systems.
Each notification provider receives a POST request with the following payload:
{
"owner": "org-name",
"name": "username",
"displayName": "John Doe",
"email": "user@example.com",
"phone": "+1234567890",
"id": "user-id",
"event": "sso-logout",
"sessionIds": ["session-123", "session-456"],
"accessTokenHashes": ["hash-abc", "hash-def"],
"nonce": "random-nonce-xyz",
"timestamp": 1699900000,
"signature": "hmac-sha256-signature"
}
Notification fields:
sessionIds: List of session IDs being logged out (enables targeted session invalidation)accessTokenHashes: SHA-256 hashes of access tokens being invalidated. Both full SSO logout and session-level logout now include these hashes, allowing your subsystems to match them against active tokens and perform synchronized logoutnonce: Random value for replay attack protectiontimestamp: Unix timestamp when the notification was generatedsignature: HMAC-SHA256 signature computed using the application's client secret
Verifying Logout Notifications
To prevent malicious logout requests, you should verify the signature of incoming logout notifications:
// Example verification in Go
func verifyLogoutNotification(notification *SsoLogoutNotification, clientSecret string) bool {
data := fmt.Sprintf("%s|%s|%s|%d|%s|%s",
notification.Owner,
notification.Name,
notification.Nonce,
notification.Timestamp,
strings.Join(notification.SessionIds, ","),
strings.Join(notification.AccessTokenHashes, ","))
expectedSignature := hmacSHA256(clientSecret, data)
return notification.Signature == expectedSignature
}
// Example verification in JavaScript
const crypto = require('crypto');
function verifyLogoutNotification(notification, clientSecret) {
const data = `${notification.owner}|${notification.name}|${notification.nonce}|${notification.timestamp}|${notification.sessionIds.join(',')}|${notification.accessTokenHashes.join(',')}`;
const expectedSignature = crypto
.createHmac('sha256', clientSecret)
.update(data)
.digest('hex');
return notification.signature === expectedSignature;
}
Configuration
To receive logout notifications, configure a notification provider (such as Custom HTTP, Telegram, or Slack) in your Casdoor application's notification provider settings. For Custom HTTP providers:
- Set Receiver to your application's webhook endpoint (e.g.,
https://app.example.com/api/logout-webhook) - Set Method to POST
- Set Title to
content(the parameter name for the JSON payload)
Your application can then verify the signature, check the timestamp to prevent replay attacks, and use the session IDs and token hashes to perform targeted logout operations. For more details on configuring notification providers, see the Notification Providers documentation.
SSO Logout API
Endpoint
GET or POST /api/sso-logout?logoutAll=<true|false>
The SSO logout endpoint accepts both GET and POST requests, making it flexible for different integration scenarios.
Parameters
logoutAll(optional): Controls logout scope. Acceptstrue,1, or empty string (default:truefor backward compatibility)trueor1or empty: Logout from all sessions across all applications- Any other value (e.g.,
false,0): Logout from current session only
Authentication
This endpoint requires the user to be authenticated. Use any authentication method supported by Casdoor:
- Access token: Include the access token in the
Authorizationheader - Session cookie: Use the session cookie that was set during login
- Client credentials: Use the application's client ID and secret for machine-to-machine scenarios
For more details on authentication methods, see the Casdoor Public API documentation.
Request Examples
Logout from All Sessions (Default)
curl -X POST https://door.casdoor.com/api/sso-logout \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Or explicitly specify logoutAll=true
curl -X POST "https://door.casdoor.com/api/sso-logout?logoutAll=true" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"