Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force login per client with keycloak (¿best practice?)

We are currently implementing keycloak and we are facing an issue that we are not sure what’s the best way to solve it.

We have different webapps making use of the sso and that’s working fine. The problem we have is when we make log in using the sso in one webapp and then we do the same in a different webapp.

Initially this second webapp does not know which user is coming (and it’s not necessary to be logged in to make use of it). When clicking on “login”, it automatically logs in the user (by making a redirection to keycloak and automatically logging the already logged user in the other webapp). This second logging happens “transparently” to the user, since the redirection to keycloak is very fast and it’s not noticeable. This behaviour is not very user friendly.

The question is: Taking into account that this second webapp can’t know upfront which user is accessing the site (unless actively redirecting to keycloak), is it possible to force always the users to log in for a specific keycloak client? By this I mean actually ask the visitor for user/pw even if keycloak knows already them from other keycloak clients.

Thanks in advance!

like image 776
user1722670 Avatar asked Sep 15 '25 16:09

user1722670


2 Answers

In the mail listing from keycloak, they gave me a good solution but for version 4:

  1. in admin console, go to Authentication
  2. make a copy of Browser flow
  3. in this new flow, disable or delete Cookie
  4. go to Clients -> (your client) -> Authentication Flow Overrides, change Browser Flow to your new flow, click Save."
like image 164
user1722670 Avatar answered Sep 18 '25 10:09

user1722670


Use logout endpoint as a default login button action in your app and redirect uri param use for login page, where you use your specific client (of course you need proper URI encoding):

https://auth-server/auth/realms/{realm-name}/protocol/openid-connect/logout?redirect_uri=https://auth-server/auth/realms/{realm-name}/protocol/openid-connect/auth?client_id=client_id&redirect_uri=.....&other_params....

=> user will be logged out and then it will be redirected to the login page

like image 36
Jan Garaj Avatar answered Sep 18 '25 09:09

Jan Garaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!