Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keycloak, user registration. How to add the role?

Tags:

keycloak

I have an app secured by keycloak. Going to a secured page brings up a keycloak login page and the correct user/password gives the expected results.

Within the client, I have switched on user registation. So now the login page shows a register link, which displays another keycloak page allowing the user to register with name, username, email.

This "works" in that the user is added to the keycloak user database. But the application displays the error page because a role is not mapped to that user in keycloak.

What I would like to happen is to be able to add the new user to the apps own user database, associate a role with the user, perhaps do some verification of the user.

So I don't really know what keycloak is sending back to the app except that it eventually leads to /error. Is there a way to tell keycloak after a new registration contact this url where things can happen within the app?

like image 285
John Avatar asked Sep 19 '19 13:09

John


People also ask

What is a client in Keycloak?

Clients are entities that can request Keycloak to authenticate a user. Most often, clients are applications and services that want to use Keycloak to secure themselves and provide a single sign-on solution.


1 Answers

I came across similar scenario and the way I solved it was by enabling a default role to the newly added user. This role can be changed later on but with a default role in place, your flow will complete.

There are 2 ways to assign a default role in keycloak. With both these configs, whenever a new user is registered even from external service providers, they will be assigned this default role:

  1. Assign a default role directly to user:

enter image description here

  1. Assign a default group to user & map a role to that default group

enter image description here

enter image description here

Please note that Default Group & Role names in above are my own and they are not predefined in keycloak.

like image 124
tryingToLearn Avatar answered Oct 19 '22 12:10

tryingToLearn