feat(client): add endSession() for RP-initiated logout#169
Merged
Conversation
The server advertises an end_session_endpoint (GET /api/logout) but the JS client only had a local-only logout(), leaving the DarkAuth SSO session alive after an app logged out. Add endSession() which clears the local session and redirects the browser to the end_session_endpoint with id_token_hint, post_logout_redirect_uri, client_id and state. The endpoint is resolved from discovery (with an endSessionEndpoint config override and an <issuer>/api/logout fallback). logout() remains local-only. Includes unit tests, README and rp-initiated-logout doc updates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the gap reported in #168. The server already ships an
end_session_endpoint(GET /api/logout, advertised in/.well-known/openid-configuration) from #160 / #161, but@darkauth/clientonly had a local-onlylogout(). Apps that called it cleared their own tokens while the DarkAuth SSO session stayed alive, so the nextinitiateLogin()could silently re-authenticate (a problem on shared/kiosk devices).This PR adds
endSession()to the client so RPs can actually trigger RP-initiated logout.Changes
endSession(options?)— clears the local session (same aslogout()), then redirects the browser to theend_session_endpointwithid_token_hint,post_logout_redirect_uri,client_id, andstate.id_token_hintdefaults to the current session's ID token (overridable).client_idis sent wheneverpost_logout_redirect_uriis provided (defaults to the configuredclientId), matching the server's requirement that the redirect URI resolve to a client.end_session_endpointis read from discovery, with a newendSessionEndpointconfig override and an<issuer>/api/logoutfallback. Cached alongside the other resolved endpoints.logout()is unchanged (still local-only) for backwards compatibility.EndSessionOptions; addedendSessionEndpoint?toConfig.Tests
Added
src/endSession.test.ts(Node test runner) covering: discovery endpoint usage + param construction + local-session clearing, discovery fallback, config override, omission ofclient_id/post_logout_redirect_uriwhen no redirect URI is given, explicitclientIdoverride, and thatlogout()does not redirect.Tests run against the compiled output via a dedicated
tsconfig.test.json→.test-build(gitignored) so no test files land in the publisheddist.Docs
packages/darkauth-client/README.md: documentedendSession(),EndSessionOptions, theendSessionEndpointconfig field, and clarified thatlogout()is local-only.docs/rp-initiated-logout.md: added an "SDK Integration" section.Note for RPs
post_logout_redirect_urimust be registered (exact match) in the client's Post-Logout Redirect URIs allowlist on the DarkAuth server, or the endpoint returns400.