Keycloak中“完成注册”信的“欢迎”

Ole*_*iak 10 keycloak

When a user is created through the Keycloak admin console, is there a way to notify a user via email that a profile has been created and the user can finish registration following by a link? Currently, the user can get an email about profile being created only if after creation a password had been set for the user. And only after an initial login attempt. But for this login attempt, the user should know the password that was set.

小智 25

我通过为发送的电子邮件和登录页面自定义 keycloak 主题模板来完成同样的事情。这是关于如何自定义主题的Keycloak 文档

这是我如何做到的具体细节:

首先,我将 executeActions.ftl 电子邮件模板自定义为漂亮并说“欢迎使用我们的应用程序,单击下面的链接以完成您的帐户设置”。我继续使用默认基本模板中的链接和链接到期说明。您可以在https://github.com/keycloak/keycloak/blob/master/themes/src/main/resources/theme/base/email/html/executeActions.ftl查看默认的基本模板

其次,我们决定了新用户“需要”哪些标准的keycloak操作。我们决定要完成注册,用户需要执行以下操作:

  1. 接受条款和条件
  2. 输入他们的全名(更新他们的个人资料)
  3. 设置新密码

第三,我们设置 Keycloak 领域以要求所有用户完成 3 个步骤。 在 Keycloak 管理控制台中,我们将这些设置为“必需”操作(在配置-->身份验证-->必需操作下),将“条款和条件”、“更新配置文件”和“更新密码”操作标记为“已启用” ”和“默认操作”。我们还按照我们希望它们在“帐户设置”过程中出现的确切顺序放置这些操作,以便用户逐屏浏览。对于其他操作,我们取消选中默认操作。 在此处输入图片说明

第四,我自定义了以下呈现帐户设置页面的 keycloak 登录模板。嵌入在 executeActions 电子邮件中的 keycloak 生成的链接(来自第 1 步)会将用户带到这些“帐户设置”网页:

  • info.ftl - 默认值在这里。单击欢迎电子邮件中的链接后,用户最终会进入由该模板生成的页面。此页面通常呈现显示各种通用信息消息的网页,但它也呈现帐户设置过程的第一个和最后一个页面。所以我修改了它以检查 message.summary 是否与帐户设置过程的第一步或最后一步匹配。如果这是第一步,我会在页面上呈现“欢迎”文本。如果这是最后一步,我会呈现诸如“您的帐户已设置”之类的内容。点击此处登录'。请参阅下文了解我如何修改 info.ftl。
<!-- info.ftl -->
<#import "template.ftl" as layout>
<@layout.registrationLayout displayMessage=false; section>

  <#if section = "header">
    <#if messageHeader??>
      ${messageHeader}
    <#else>
      <#if message.summary == msg('confirmExecutionOfActions')>
        ${kcSanitize(msg('welcomeToOurApplication'))?no_esc}
      <#elseif message.summary == msg('accountUpdatedMessage')>
        ${kcSanitize(msg('accountSuccessfullySetup'))?no_esc}
      <#else>
        ${message.summary}
      </#if>
    </#if>

  <#elseif section = "form">
    <div id="kc-info-message">
      <div class="kc-info-wrapper">
        <#if message.summary == msg('confirmExecutionOfActions')>
          ${kcSanitize(msg('startSettingUpAccount'))?no_esc}
        <#elseif message.summary == msg('accountUpdatedMessage')>
          ${kcSanitize(msg('accountIsReadyPleaseLogin'))?no_esc}
        <#else>
          ${message.summary}
        </#if>
      </div>

      <#if pageRedirectUri??>

       ... <!-- Omitted the rest because it's the same as the base template -->

Run Code Online (Sandbox Code Playgroud)

我还自定义了以下模板,它们对应于帐户设置过程中的步骤。

  • term.ftl - 显示条款和条件步骤
  • login-update-profile.ftl - 显示用户需要输入/更新他/她的全名的步骤
  • login-updated-password.ftl - 提示用户更改密码。

第五,当管理员创建一个新用户时,他/她会触发发送给该用户的欢迎电子邮件: - 在 Keycloak 管理控制台中,一旦您“添加”一个新用户,请转到该用户的“凭据”选项卡,然后在凭据重置在“重置操作”下选择所需的帐户设置操作,然后单击“发送电子邮件”按钮。

项目清单

无论如何,我希望这会有所帮助。我记得我花了一点时间才弄明白,因为它不是 keycloak 中的标准流程。

  • 我相信您可以使用 keycloak api 发送验证电子邮件,这可能会消除其他人发送电子邮件的需要。 (2认同)