Simon Schürg
Simon Schürg

Reputation: 2263

How to access OIDC client information in Keycloak 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

password reset page

The information is set on the client:

keycloak web ui client settings

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

rendering error

# 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?

Upvotes: 1

Views: 743

Answers (1)

EsseBé
EsseBé

Reputation: 41

Yep, client segment seems not accessible and give https://null !

But if you check availabilty of segment it is not empty!

<#if client?? && client['baseUrl']?? && client['baseUrl']?has_content>
  <img height="100" src='${client["rootUrl"]}/${kcSanitize(msg("emailSignatureLogoUrl"))?no_esc}' style="max-width: 250px;">
<#else>
  <img height="100" src='${kcSanitize(msg("emailSignatureLogoUrl"))?no_esc}' style="max-width: 250px;">
</#if>

This is the same result with client['rootUrl']

Searching an anwser, I have found this topics about Model provisioning for EmailTemplate: https://keycloak.discourse.group/t/access-to-group-attributes-in-custom-email-template/10874/2

Upvotes: 1

Related Questions