How can I load user data in a Keycloak .ftl template?

Viewed 964

I have a custom login-update-password.ftl file. I want to show the user's firstname and lastname. In the template file of the base example I see ${username} which lets me show the username. But when I do ${firstname}, following happens:

12:25:46,752 ERROR [freemarker.runtime] (default task-3) Error executing FreeMarker template: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> firstname  [in template "login-update-password.ftl" at line 14, column 3]

When I do ${user.firstname}, following happens:

12:27:40,453 ERROR [freemarker.runtime] (default task-2) Error executing FreeMarker template: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> user  [in template "login-update-password.ftl" at line 14, column 3]

I debugged the available variables, but nothing seems to be what I need.

<#list .data_model?keys as key>
  ${key}
</#list>
msg
execution
social
auth
isAppInitiatedAction
requiredActionUrl
message
locale
authenticatorConfigured
login
url
messagesPerField
client
realm
kcSanitize
scripts
properties
username

How can I load more user data?

1 Answers

Instead of (user.firstname) try the getFirstName method. ex: user.getFirstName()

Related