Reputation: 319
For password reset link keycloak by default shows link expiration time minutes but we want to show that in hours.
For this, we have made modification in keycloak email theme .ftl file (password-reset.ftl). These changes are working fine if we do that in keycloak base email theme (/opt/keycloak/themes/base/email). But these changes are getting discarded after keycloak deployment/upgrade.
To avoid this we have moved this theme to custom theme folder (/opt/keycloak/themes/mytheme/email) and chosen custom email theme for an email from keycloak admin realm theme configuration but still, keycloak not using a custom theme for an email.
File: themes/mytheme/email/html/password-reset.ftl
code that displays time in hours instead of minutes:
<html>
<body>
${msg("passwordResetBodyHtml",link, (linkExpiration/60)?string["0"], realmName)?no_esc}
</body>
</html>
Selected mytheme for an email from keycloak realm configuration configuration screenshot here
Upvotes: 1
Views: 3169
Reputation: 700
To format your time for minutes, hours, days a better approach is to pass linkExpirationFormatter(linkExpiration)
to the msg function and add time unit translations to the messages_xx.properties file like:
linkExpirationFormatter.timePeriodUnit.seconds=seconds
linkExpirationFormatter.timePeriodUnit.seconds.1=second
linkExpirationFormatter.timePeriodUnit.minutes=minutes
linkExpirationFormatter.timePeriodUnit.minutes.1=minute
linkExpirationFormatter.timePeriodUnit.hours=hours
linkExpirationFormatter.timePeriodUnit.hours.1=hour
linkExpirationFormatter.timePeriodUnit.days=days
linkExpirationFormatter.timePeriodUnit.days.1=day
Upvotes: 0