8

In the base templates of the Keycloak there are multiple examples of variables, that are accessed in the Freemarker Templates. For example, in the file: https://github.com/keycloak/keycloak/blob/master/themes/src/main/resources/theme/base/login/login.ftl

There are fields:

properties.kcFormGroupClass

realm.rememberMe

url.registrationUrl

Where are those hashes defined? The only thing I found in the documentation was that I can access:

${some.system.property} - for system properties

${env.ENV_VAR} - for environment variables

but I cannot find f.e. url options. I would like to display the address that the user tries to access.

Community
  • 1
  • 1
JoshThunar
  • 452
  • 1
  • 6
  • 15

1 Answers1

5

All this entities is as instances of Java Classes that was provided for Freemarker template engine during page rendering. You can search for corresponding classes in keycloak github repo. Usually they all named like %Something%Bean e.g. LoginBean, ClientBean, UrlBean.

look here: https://github.com/keycloak/keycloak/blob/10.0.1/services/src/main/java/org/keycloak/forms/login/freemarker/model/RealmBean.java

solveMe
  • 1,866
  • 1
  • 18
  • 20
  • Thank you. Just to close the question - is it possible to display the address the user is trying to access? I've checked all the login forms and I couldn't find such field. Root url would be also sufficient for my display purposes, but it is a private property as I'm checking. – JoshThunar May 11 '20 at 12:16
  • 3
    It be really helpful to at least know which beans are available to which templates. – thelr Nov 17 '20 at 14:55
  • 1
    @thelr I believe you can check the FreeMarker Providers in directories above. Those beans should be simply imported, f.e.: https://github.com/keycloak/keycloak/blob/master/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java https://github.com/keycloak/keycloak/blob/master/services/src/main/java/org/keycloak/forms/login/freemarker/FreeMarkerLoginFormsProvider.java – JoshThunar Nov 30 '20 at 12:48
  • @JoshThunar AFAIR I added IP address info (remote/local addr) as freemarker attribute explicitly via implementing custom EmailTemplateProvider (actually I extended default one). URLs/IP info I obtained from Keycloak Context object. – solveMe Sep 07 '21 at 01:16
  • Thanks, for this solution I used a small script https://stackoverflow.com/questions/61748844/get-root-url-in-keycloak-login-theme – JoshThunar Sep 07 '21 at 22:25
  • seems that not all are available, e.g. clientbean is null when no session available – leachim Sep 10 '21 at 14:43