Keycloak - access to context variables in email template

Viewed 425

I am using ready image of keycloak 11.0.x from dockerhub, so I am not changing java code, I just configure image and run. The only thing I modify is executeActions.ftl email template, and everythings works! My template with email message is changed, but I would like to have access to roles and groups from this template... to change it even more.

I know from other templates that I have access to few variables/methods in this template like: link, linkExpiration, realmName, requiredActions, linkExpirationFormatter(linkExpiration), event.date, event.ipAddress, and few more.

I found one more variable: user.attributes.xxxx, but I have no idea what other variables are available here. I cloned current keycloak repository, and started to analyse code, but I found it little hard to understand everything, because I am programing in python.

On stackoverflow I also found something like this: <variable>.getClass().getDeclaredFields(), and this method prints all object attributes and it helped me in analysing code at start.

I also found that in templates:

  • user variable is ProfileBean object and it does not contain groups
  • requiredActions seems to be declared in CachedUser class but I have no acces to other variables from this class
  • user.attributes.xxxx is just specially prepared constant that is added to context somewhere
  • EDIT: I also found that almost all attributes are added in FreeMarkerEmailTemplateProvider class, and here I found few more like: locale, properties, msg, but still this is not all, I don't know where are declared context variables always available in templates - search still in progress

I believe there are a loads of variables somewhere in context data, but I have no idea where they are declared, and how to access them. I am still analysing code, but decided to ask here because it is probably obvious to someone who already is working with keycloak code.

I will appreciate any help! Thank you!

0 Answers
Related