Better Logout Experience #466
Labels
No labels
API
Billing
UI/UX
dependencies
bug
change
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
servala/servala-portal#466
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stories
As a user, I want to have a great experience when logging out
Implementation Notes
Right now logging out only logs out of the portal, but not from Keycloak. We should have full blown logout.
Problem
When a user logs out, only the Django session is cleared. The Keycloak SSO session remains active. This means:
Root Cause
The current
LogoutView(src/servala/frontend/views/auth.py) only callsflows.logout.logout(request), which clears the Django session but does not communicate with Keycloak's OIDC logout endpoint.Goal
After logout, the Keycloak SSO session should also be terminated so that the next sign-in requires entering credentials again.
Technical Context
id_tokenJWT string anywhere accessible after login - by the time standard hooks fire (pre_social_login), it has been decoded into a dict inSocialAccount.extra_data["id_token"]SOCIALACCOUNT_STORE_TOKENSstoresaccess_tokenandrefresh_tokeninSocialToken, but not the rawid_tokenend_session_endpointis available via the OpenID Connect discovery document (already fetched by allauth during login)end_session_endpointrequires the portal's post-logout redirect URI to be registered in the Keycloak client settings under "Valid Post Logout Redirect URIs"Options
Option A: Store raw
id_tokenin session during login, use asid_token_hintSubclass
OpenIDConnectOAuth2Adapterand overridecomplete_loginto save the raw JWT into the Django session before it gets decoded:Register a custom OIDC callback URL pattern (before the allauth include) that uses this adapter. At logout, read the raw
id_tokenfrom the session, then redirect to:id_tokenmay expire (typically 5-15 min), but Keycloak still accepts expiredid_token_hintfor logout.Option B: Use
client_idparameter instead ofid_token_hintSince Keycloak 18+, the
end_session_endpointacceptsclient_idas an alternative toid_token_hint. At logout, redirect to:SERVALA_KEYCLOAK_CLIENT_ID).id_token_hint, Keycloak may show a "Do you want to log out?" confirmation page instead of silently logging out.client_idparameter is Keycloak-specific, not part of the OIDC spec.Option C: Combine both (A with B as fallback)
Store the raw
id_tokenin the session (Option A), but if it's not available (e.g. sessions created before deployment), fall back toclient_id(Option B).References