Skip to content

Commit faf4ce7

Browse files
committed
Document Session Logout Support
Issue gh-14904 Issue gh-13841
1 parent 8545b53 commit faf4ce7

File tree

1 file changed

+122
-0
lines changed
  • docs/modules/ROOT/pages/servlet/oauth2/login

1 file changed

+122
-0
lines changed

docs/modules/ROOT/pages/servlet/oauth2/login/logout.adoc

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,128 @@ The overall flow for a Back-Channel logout is like this:
223223
Remember that Spring Security's OIDC support is multi-tenant.
224224
This means that it will only terminate sessions whose Client matches the `aud` claim in the Logout Token.
225225

226+
One notable part of this architecture's implementation is that it propagates the incoming back-channel request internally for each corresponding session.
227+
Initially, this may seem unnecessary.
228+
However, recall that the Servlet API does not give direct access to the `HttpSession` store.
229+
By making an internal logout call, the corresponding session can now be validated.
230+
231+
Additionally, forging a logout call internally allows for each set of ``LogoutHandler``s to be run against that session and corresponding `SecurityContext`.
232+
233+
=== Customizing the Session Logout Endpoint
234+
235+
By default, the session logout endpoint is `+{baseScheme}://localhost{basePort}/logout+`.
236+
The `LogoutHandler` will collect the stored CSRF token and session identifier and populate them into a back-end call that allows the corresponding session to be invalidated.
237+
238+
Given that propagating the CSRF token can be a challenge, a new configuration point was released in 6.4 which defaults the endpoint to `+{baseUrl}+/logout/connect/back-channel/+{registrationId}+`.
239+
You can activate this in the following way:
240+
241+
242+
[tabs]
243+
======
244+
Java::
245+
+
246+
[source=java,role="primary"]
247+
----
248+
http
249+
// ...
250+
.oidcLogout((oidc) -> oidc
251+
.backChannel((backChannel) -> backChannel
252+
.sessionLogout(Customizer.withDefaults())
253+
)
254+
);
255+
----
256+
257+
Kotlin::
258+
+
259+
[source=kotlin,role="secondary"]
260+
----
261+
http {
262+
oidcLogout {
263+
backChannel {
264+
sessionLogout { }
265+
}
266+
}
267+
}
268+
----
269+
======
270+
271+
In the event that you need to customize the endpoint, you can provide the URL as follows:
272+
273+
274+
[tabs]
275+
======
276+
Java::
277+
+
278+
[source=java,role="primary"]
279+
----
280+
http
281+
// ...
282+
.oidcLogout((oidc) -> oidc
283+
.backChannel((backChannel) -> backChannel
284+
.sessionLogout((session) -> session
285+
.uri("http://localhost:9000/logout/connect/back-channel/+{registrationId}+")
286+
))
287+
)
288+
);
289+
----
290+
291+
Kotlin::
292+
+
293+
[source=kotlin,role="secondary"]
294+
----
295+
http {
296+
oidcLogout {
297+
backChannel {
298+
sessionLogout {
299+
uri = "http://localhost:9000/logout/connect/back-channel/+{registrationId}+"
300+
}
301+
}
302+
}
303+
}
304+
----
305+
======
306+
307+
=== Customizing the Session Logout Cookie Name
308+
309+
By default, the session logout endpoint uses the `JSESSIONID` cookie to correlate the session to the corresponding `OidcSessionInformation`.
310+
311+
However, the default cookie name in Spring Session is `SESSION`.
312+
313+
You can configure Spring Session's cookie name in the DSL like so:
314+
315+
[tabs]
316+
======
317+
Java::
318+
+
319+
[source=java,role="primary"]
320+
----
321+
http
322+
// ...
323+
.oidcLogout((oidc) -> oidc
324+
.backChannel((backChannel) -> backChannel
325+
.sessionLogout((session) -> session
326+
.cookieName("SESSION")
327+
))
328+
)
329+
);
330+
----
331+
332+
Kotlin::
333+
+
334+
[source=kotlin,role="secondary"]
335+
----
336+
http {
337+
oidcLogout {
338+
backChannel {
339+
sessionLogout {
340+
cookieName = "SESSION"
341+
}
342+
}
343+
}
344+
}
345+
----
346+
======
347+
226348
=== Customizing the OIDC Provider Session Registry
227349

228350
By default, Spring Security stores in-memory all links between the OIDC Provider session and the Client session.

0 commit comments

Comments
 (0)