-
Hi, I have another question :-) Within my BFF (which implements Spring Cloud Gateway) I would like to intercept back-channel logout calls coming from my Keycloak instance (v. 26.0.7). I would like to be able to perform some sort of callback. back-channel-logout:
enabled: true
internal-logout-uri: ${client-uri}/logout/connect/back-channel/${client-id} Thank you very much |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
All that For instance, let's consider:
The OAuth2 client for the BFF is configured in Keycloak with a Back-Channel Logout of The BFF is configured with When logging out from Keycloak user account management UI at https://localhost/auth/realms/{realmId}/account, a Back-Channel Logout event is sent by Keycloak to the BFF (skipping the reverse proxy and its self-signed certificate which might not be added to the cacerts of the container JRE Keycloak is running into). This request:
The BFF finds the session using the information from the token contained in the Back-Channel Logout request body and loops to itself, but this time with the session cookie to end the session, just as if it was an authorized request from the user's agent, instead of an anonymous request from the Keycloak server. So, you'll have to choose which of the 2 Back-Channel Logout requests to hook into (the anonymous request from Keycloak or the authorized internal loop). And I'm afraid that you'll have to dive into Spring Security implementation to figure out how. May I ask what you are trying to do with this callback? |
Beta Was this translation helpful? Give feedback.
-
This looks like the key point: what you are ultimately interested in are session events. Logout events are just one of the possible causes for sessions being destroyed. If working with a single instance BFF, the servlet version of Spring Cloud Gateway can greatly help because you could listen to the container's If working with a clustered BFF, you should also look into Spring Session project. When the gateway is distributed for scalability or high availability, so should its sessions. As a session deletion event should be emitted only once for the cluster and not once per instance (or replica, pod, or whatever you name what is part of the same clustered BFF), the callback to other components of the system should be triggered from the shared sessions handling (Spring Session). |
Beta Was this translation helpful? Give feedback.
This looks like the key point: what you are ultimately interested in are session events. Logout events are just one of the possible causes for sessions being destroyed.
If working with a single instance BFF, the servlet version of Spring Cloud Gateway can greatly help because you could listen to the container's
SessionDestroyedEvent
using a SpringApplicationListener
.If working with a clustered BFF, you should also look into Spring Session project. When the gateway is distributed for scalability or high availability, so should its sessions. As a session deletion event should be emitted only once for the cluster and not once per instance (or replica, pod, or …