Direct registration page link?

Turns out that if you enable registration on your realm you can still generate a URL like this

Direct registration url

http://<domain.com>/realms/<realm-name>/protocol/openid-connect/registrations?client_id=<client_id>&response_type=code&scope=openid email&redirect_uri=http://<domain.com>/<redirect-path>&kc_locale=<two-digit-lang-code>

(notice how the /auth part is no longer present where it was present in earlier versions of keycloak).

It’s a simple way to pop a registration page but there are some drawbacks :

  • This doesn’t seem to be a documented / supported feature but rather just some internal url that is used. I know the JS adapter generates it, but if you rely on a backend to generate such a URL things can break with future keycloak releases if they decide to change this url
  • You need to open up registrations completelty to all users (you cannot limit the invitation / registration to a specific user

execute-actions-email REST call

An alternative is to use the execute-actions-email REST call, that allows you to have keycloak send out an email for a particular keycloak user containing a link allowing him/her to perform the signup / registration

Advantages with that :

  • You don’t need to open up the registration completely. (on the realm settings you can disable registration).
  • You can target specific users and put expirations on the signup link.

Disadvantage

  • Keycloak becomes responsible for sending out the email. If you want to have more control this endpoint is not for you

Other ways ?

If you look at the code behind the execute-actions-email endpoint, the following is done to build that unique / user specific / time limited registration url

KeycloakSession session; // retrieve the session somewhere.
RealmModel realm; // retrieve the realm model somewhere.
ExecuteActionsActionToken token = new ExecuteActionsActionToken(user.getId(), user.getEmail(), expiration, actions, redirectUri, clientId);
UriBuilder builder = LoginActionsService.actionTokenProcessor(session.getContext().getUri());
builder.queryParam("key", token.serialize(session, realm, session.getContext().getUri()));
String link = builder.build(realm.getName()).toString();

It might be possible to create a custom REST resource on keycloak that you can call (using some kind of client credentials flow) that would allow you to return such a URL for a particular user. (that’s what I am currently investigating).