Create logout URL for browsers
Endpoint
This endpoint is only for browser clients. For API clients (mobile apps, etc.), use the
/self-service/logout/api endpoint instead.Query parameters
URL to redirect the browser to after logout completion.
Headers
Session cookie. If missing or invalid, returns 401 error.
Response
Logout token to be used when calling the logout endpoint.
The URL to perform the logout. Typically
GET /self-service/logout?token=....Status codes
| Status | Description |
|---|---|
| 200 | Logout flow initialized, returns logout token |
| 400 | Invalid request |
| 401 | No active session |
| 500 | Internal server error |
Usage
After receiving the logout token, redirect the user’s browser to thelogout_url or call the logout endpoint with the token:
Perform logout for browsers
Endpoint
Query parameters
The logout token from the
/self-service/logout/browser endpoint.URL to redirect to after logout. Overrides the return_to from flow initialization.
Headers
Session cookie.
Response
The response depends on theAccept header:
Without Accept: application/json:
- 303 redirect to the
return_toURL or default redirect URL - Session cookie is cleared
Accept: application/json:
- 204 No Content on successful logout
- No response body
- Session cookie is cleared
Status codes
| Status | Description |
|---|---|
| 204 | Successful logout (JSON requests) |
| 303 | Redirect to return_to URL (browser requests) |
Perform logout for native apps
Endpoint
Request body
The Ory Session Token to revoke.
Response
Returns 204 No Content on success. A 204 response is also returned if the session token was already revoked.Status codes
| Status | Description |
|---|---|
| 204 | Session token revoked successfully |
| 400 | Invalid request or malformed token |
| 403 | Token is invalid or does not exist |
Usage example
Browser vs API logout comparison
| Feature | Browser flow | API flow |
|---|---|---|
| Endpoint | GET /self-service/logout/browser then GET /self-service/logout | DELETE /self-service/logout/api |
| Authentication | Session cookie | Session token in request body |
| Response | Redirect or 204 | 204 No Content |
| Cookies | Clears HTTP cookies | Does not affect cookies |
| Use case | Web applications | Mobile apps, CLIs, backend services |
Security considerations
Browser logout
- Always use the two-step process: get token, then logout with token
- The logout token is short-lived and single-use
- Session cookies are properly cleared on logout
- CSRF protection is maintained through the token mechanism
API logout
- Store session tokens securely (encrypted storage, keychain, etc.)
- Clear session tokens from local storage after logout
- Session token revocation is immediate
- Consider implementing token refresh for long-lived sessions
Error handling
Both logout endpoints are designed to be idempotent:- Logging out an already-logged-out session returns success (204)
- Using an invalid token returns an error
- Using an expired token returns an error