Automatic login after Register

Hi mates,

I’m developing a Spring Boot backend and an Angular frontend application. My goal is to automatically log in after user registration. My registration process involves registering the user via a REST API using the backend.
How can I achieve automatic login to angular application after registration? I’m using the Keycloak Angular plugin.

1 Like

I have a similar use case and am interested in any hints how to approach a solution.

One option I figured out, but want to avoid, would be to activate the “Direct Access Grant” (Resource Owner Password Credentials Grant) for the angular related client.

I am wondering if there is any other solution available.

Keycloak has user registration capabilities. The standard way is to do the registration with keycloak.

Instead of using a REST API, you can use the user registration endpoint https://{kc-domain}/realms/{realm-name}/protocol/openid-connect/registrations, with parameters similar to a standard login federation. For example:

http://{kc-domain}/realms/{realm-name}/protocol/openid-connect/registrations
  ?client_id={client-id}
  &response_type=code
  &scope=openid
  &redirect_uri={redirect-uri}
  &kc_locale=en

Instead of seeing the user login form, you will see the user registration form.
Once successfully registered, Keycloak will automatically create a session

1 Like

The standard way is to do the registration with keycloak.

@jean.silga not sure why this should be the standard way, but anyway we are not using the registration feature of keycloak but rather route the registration process through one of our backend apis and create the user on keycloak via its REST api :smiley:

Instead of using a REST API, you can use the user registration endpoint

Instead of seeing the user login form, you will see the user registration form.

@embesozzi as mentioned above, we are not using keycloaks registration features and changing our implementation to use them is not an option atm.

But I think I found a possible solution yesterday evening which I have to investigate further, Token Exchange would allow us to send a token from our own API to our mobile app which exchanges it with an access / id token and logs in the user.

Another option could be, during registration, it is common and recommended to validate the user’s email. Therefore, you can create the user and then send a Magic Link (it’s required to use a custom SPI). It will help you to validate the information and create a session.
In relation to the Magic Link, here is the link to this lovely SPI:

Just to provide other options to consider.