Logout
| This documentation was generated with the assistance of AI. Please report any inaccuracies. |
Signing out involves two sessions: the relying party’s (here the BFF session that holds the tokens) and the
authorization server’s own login session. The repository supports three ways out. The SPA signs out with
POST /bff/logout, which ends the BFF session and then sends the browser to the OpenID Connect RP-initiated logout
endpoint of auth-server (/connect/logout), which ends the server session and returns the browser to a
registered post-logout redirect URI. A user of the server’s own pages can also sign out there directly, through the
/logout confirmation page. Back-channel and front-channel logout are not implemented.
At a glance
| Item | Value |
|---|---|
Actors |
User and browser (the SPA served by the |
Clients |
|
Preconditions |
The client’s post-logout redirect URIs: |
Endpoints |
BFF: |
Steps
Sign-out from the SPA (RP-initiated)
-
The SPA builds a
<form method="post" action="/bff/logout">with a hidden_csrffield copied from theXSRF-TOKENcookie and submits it as a top-level navigation. -
The BFF chain’s logout filter (configured in
SecurityConfig.bffFilterChain, matching onlyPOST /bff/logout) runs its handlers: it clears theXSRF-TOKENcookie and the security context and invalidates the session, which deletes it from thespring_sessiontable, tokens included. -
OidcClientInitiatedLogoutSuccessHandler(LogoutConfiguration) answers302to theend_session_endpointit read from the discovery document, withid_token_hint(the session’s ID token) andpost_logout_redirect_uri({baseUrl}/, the root of the SPA). -
The browser follows the redirect to
/connect/logout. Spring Authorization Server finds the authorization that issued the ID token, checks that itsaudis the client, and, when the browser still has a server session, that the token’ssubandsidmatch that session; then it checks thatpost_logout_redirect_uriis one of the client’s registeredpostLogoutRedirectUris. -
It ends the server session (security context cleared, session invalidated) and redirects to the post-logout redirect URI, adding
statewhen the request carried one. The SPA loads in its signed-out state and does not start a new sign-in by itself.
Sign-out on the authorization server pages
-
A signed-in user opens
GET /logout.LogoutControllerrenderstemplates/logout.html, whose form posts to/logoutwith the CSRF token added byth:action. -
POST /logout, configured byLogoutChainCustomizeron the login chain, invalidates the session, deletes theJSESSIONIDcookie and redirects to/login?logout. A post without the CSRF token is refused with403and the session is kept.
The BFF’s logout handler:
/**
* Builds the handler that redirects the browser to the logout URL of the authorization server (its
* {@code end_session_endpoint}, with {@code id_token_hint} and {@code post_logout_redirect_uri}), with the default
* redirect strategy: the answer to {@code POST /bff/logout} is a {@code 302} that the browser follows as a
* top-level navigation, so no script ever reads the ID token the URL carries.
*
* @param clientRepository the registered OAuth2 clients.
* @return the logout success handler.
*/
@Bean
OidcClientInitiatedLogoutSuccessHandler oidcLogoutSuccessHandler(
final ClientRegistrationRepository clientRepository) {
final var handler = new OidcClientInitiatedLogoutSuccessHandler(clientRepository);
handler.setPostLogoutRedirectUri(POST_LOGOUT_REDIRECT_URI);
return handler;
}
The server’s own logout:
@Override
public void customize(final HttpSecurity http) {
http.logout(logout -> logout
.logoutUrl(LOGOUT_PATH)
.logoutSuccessUrl(LOGOUT_SUCCESS_URL)
.invalidateHttpSession(true)
.deleteCookies(SESSION_COOKIE));
}
Tokens and claims
No token is issued. The ID token travels as id_token_hint in the URL of a top-level navigation only, never in a
response a script can read; BffEndToEndIT allows it there and nowhere else. The logout ends sessions; it does not
revoke the authorization stored on the server, so a copied refresh token stays valid until it expires or is revoked
(/oauth2/revoke). The BFF no longer holds any token once its session is invalidated.
What is not implemented:
-
Back-channel logout: the server sends no
logout_token, so another client’s session survives a sign-out of the server until it expires. -
Front-channel logout: not supported by Spring Authorization Server.
How it is tested
-
auth-server/bootLogoutIT: the confirmation page,POST /logoutinvalidating the session, refused without CSRF, and/connect/logoutredirecting to a registeredpost_logout_redirect_uriwithstate(session invalidated) or refusing an unregistered one without redirecting (session kept). -
bff/bootSecurityConfigIT: the sign-out form with the raw_csrfparameter ends the session and redirects; aGET /bff/logoutis not handled. -
bff/bootSpaStaticResourcesIT: the SPA signs out with a form post. -
e2e-testsBffEndToEndIT: signs in and out through the real servers, lands on the signed-out SPA, and checks that/bff/userand/api/documentsanswer401.