How to access OIDC client information in E-Mail templates?

I know how to access some variable information in Keycloak E-Mail templates. E.g.:

user.getUsername()
user.getEmail()
user.getFirstName()
user.getLastName()

But I need to access client specific variables. The Keycloak Java Code shows there is all information I need in the ClientModel Java Class: https://github.com/keycloak/keycloak/blob/main/server-spi/src/main/java/org/keycloak/models/ClientModel.java

client.getClientId()
client.getName()
client.getDescription()
client.getRootUrl()
client.getBaseUrl()
client.getAttribute(name)

And the client_id=account Query Parameter is also set on the page, where the password reset action is triggered:

https://example.com/auth/realms/my-realm/login-actions/reset-credentials?client_id=account&tab_id=bQiVx012SZg

image

The information is set on the client:

image

But the client varaible seems to be unset while the email template gets rendered.

# password-reset.ftl

# This does NOT work
${client.name}

# This does NOT work
${kcSanitize(msg("clientinfohtml",client.getName()))?no_esc}

How to access client variables in Keycloak E-Mail templates?

The defaults are implemented in the FreeMarkerEmailTemplateProvider. If this isn’t enough for you, you’ll have to implement your own custom EmailTemplateProvider (with according factory class of course) and register it properly.