keycloak - 如何在自定义电子邮件模板主题中添加领域名称

标签 keycloak

我已经为 Keycloak 电子邮件创建了一个自定义主题。

我知道如何在电子邮件正文中添加领域名称,但我没有找到如何在主题中添加领域名称。

是否有可能在不需要自定义提供程序的情况下添加此内容?

谢谢!

最佳答案

有同样的问题。

因此进行了一些研究(通过代码),并发现在编写此答案时,默认的基于 Freemarker 的电子邮件实现甚至不提供主题属性(称为变量或参数)以及最终主题字符串格式化是基于空属性列表完成的。 https://github.com/keycloak/keycloak/blob/bfce612641a70e106b20b136431f0e4046b5c37f/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java#L162

 @Override
    public void sendExecuteActions(String link, long expirationInMinutes) throws EmailException {
        Map<String, Object> attributes = new HashMap<>(this.attributes);
        attributes.put("user", new ProfileBean(user));
        addLinkInfoIntoAttributes(link, expirationInMinutes, attributes);

        attributes.put("realmName", getRealmName());

        send("executeActionsSubject", "executeActions.ftl", attributes);
    }

返回调用

    @Override
    public void send(String subjectFormatKey, String bodyTemplate, Map<String, Object> bodyAttributes) throws EmailException {
        send(subjectFormatKey, Collections.emptyList(), bodyTemplate, bodyAttributes);
    }

最后,这个函数被执行

 protected EmailTemplate processTemplate(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) throws EmailException {
        try {
........
            String subject = new MessageFormat(rb.getProperty(subjectKey, subjectKey), locale).format(subjectAttributes.toArray());
........

executeAction 的代码跟踪中,我找不到任何允许在主题行中添加动态值/变量的逻辑。

为了解决这个问题,我提出了一个问题。完成后我会链接它。

更新 1

问题已打开:https://github.com/keycloak/keycloak/issues/11883

更新2

公关提升:https://github.com/keycloak/keycloak/pull/11885

关于keycloak - 如何在自定义电子邮件模板主题中添加领域名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72058054/

相关文章:

ldap - 将 LDAP 特定属性映射到 Keycloak 角色

spring-security - 微服务到微服务调用,来自队列消息的授权

spring-boot - Spring Keycloak 适配器权限策略执行器。如何设置

java - 使用 Keycloak SSO 在 2 个应用程序之间保持身份验证

java - 如何通过 ID 获取其他用户信息(用户名、名字)? [ key 斗篷]

spring-boot - 在Spring Boot中获取Keycloak的AccessToken

single-sign-on - key 斗篷 : Single Logout(SLO)

keycloak - 如何在keycloak主题中使用我自己的常用文件?

spring - 在 WebMvcTest 中为 Keycloak 加载自定义 SecurityConfig 时的 NPE

kubernetes - 在不同的 Keycloak 实例之间同步用户