-
Hi, I'm following the BFF tutorial (https://www.baeldung.com/spring-cloud-gateway-bff-oauth2) and I want to use BFF as an OAuth2 client. I would like to implement a web page logout with a single call, without having to perform a POST to /logout and then a redirect to the URL retrieved from the 'location' header. I probably don't understand the backchannel-logout mechanism very well. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 6 replies
-
Possibly related to this? |
Beta Was this translation helpful? Give feedback.
-
User logout from an OAuth2 systemUsers have sessions on the authorization server and on each OAuth2 client with which they use authorization code flow. So, that's a minimum of two sessions to close (the one on the BFF and the one on Keycloak in your case). RP-Initiated LogoutThis is the mechanism used in the tutorial. As exposed in the spec:
In the case of the tutorial, the relying party (RP) is the BFF and the OpenID provider (OP) is Keycloak. Purpose of the Back-Channel LogoutThis is designed to provide single sign-out in "Single Sign-On" environment: in the case where a user has authorized sessions on several OAuth2 clients, when he logs out from one of these clients, the authorization server can notify other clients through Back-Channel Logout. A notable difference with RP-Initiated Logout is that it is direct communication from the OP to RPs (user agent is not used). This of course requires that RPs are server applications (which is the case of a BFF). A sample would be if we decided to use a different BFF instance for each of the three apps in the tutorial. A flow could look something like that:
Logging the user out with a single user agent requestAn option is using Keycloak's "logout" form and Back-Channel Logout to notify the BFF. Another option would be using Keycloak's admin API in a custom The inconvenient of both of these methods compared to RP-Initiated Logout is that it is not part of the OpenID standard: if you change to something else than Keycloak, maybe you can't keep the same flow, even if the new authorization server complies with OIDC. My adviceJust stick to RP-Initiated Logout as defined in OpenID standard and implemented in the tutorial and have the user agent follow the redirections. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, Continuing to read the answers to: spring-projects/spring-security#14679 I realized that I could solve it using the internal host and port, without going through the reverse-proxy: And indeed, it seems to work, using, for example: I'm a little undecided about which solution to adopt.... |
Beta Was this translation helpful? Give feedback.
-
Sorry for the images.. Yes, /logout is needed:
Now it works perfectly. Regarding the original question: This web application, in case of tab or browser closure makes a call to the backend, to logout, intercepting I would have liked to replicate the old behavior with a single call, because I am afraid (but I would have to verify it) that with two calls it may happen to close the session on BFF, but leave it active on Keycloak.. |
Beta Was this translation helpful? Give feedback.
-
It is not one application, but about 20 web applications (WAR) deployed in a Wildfly application server, developed with Spring Framework (not Spring Boot). Do you think there are more suitable solutions? I am still in the study and testing phase. |
Beta Was this translation helpful? Give feedback.
-
I tried to activate Back-Channel Logout to the Docker stack of the Baeldung article but hit a major limitation: Back-Channel Logout fails with cookie-based CSRF protection. As a side note, it is very unsafe to disable CSRF protection in a security filter-chain with Fortunately, as your applications are rendered on the server, you can use session store for CSRF tokens. |
Beta Was this translation helpful? Give feedback.
-
You are absolutely right ! |
Beta Was this translation helpful? Give feedback.
User logout from an OAuth2 system
Users have sessions on the authorization server and on each OAuth2 client with which they use authorization code flow. So, that's a minimum of two sessions to close (the one on the BFF and the one on Keycloak in your case).
RP-Initiated Logout
This is the mechanism used in the tutorial. As exposed in the spec:
In the case of the tutorial, the relying party (RP) is the BFF and the OpenID provider (OP) is Keycloak.
Purpose of the Back-Channel Logout
This is designed to provide single sign-out in "Single Sign-On" environment: in the case wh…