Keycloak 中 "Finish registration" 个字母的 "Welcome" 个

"Welcome" of "Finish registration" letter in Keycloak

当通过 Keycloak 管理控制台创建用户时,有没有办法通过电子邮件通知用户配置文件已创建并且用户可以在 link 之后完成注册? 目前,只有在创建后为用户设置了密码,用户才能收到有关正在创建配置文件的电子邮件。并且仅在初始登录尝试之后。但是对于这次登录尝试,用户应该知道设置的密码。

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

以下是我的具体做法:

首先,我将 executeActions.ftl 电子邮件模板 自定义为漂亮的 "welcome to our application, click the link below to finish setting up your account"。我继续使用默认基本模板中的 link 和 link 到期说明。您可以在 https://github.com/keycloak/keycloak/blob/master/themes/src/main/resources/theme/base/email/html/executeActions.ftl

查看默认的基本模板

其次,我们决定了新用户 "required" 的标准密钥斗篷操作 。我们决定要完成注册,用户需要执行以下操作:

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

第三,我们设置 Keycloak 领域要求所有用户完成这 3 个步骤。 在 Keycloak 管理控制台中,我们将这些设置为 "Required" 操作(在 Configure-->Authentication-->Required Actions 下),标记 "Terms and Conditions"、"Update Profile" 和 "Update Password" "Enabled" 和 "Default Action" 的动作。我们还按照我们希望它们出现在用户将逐屏浏览的 "account setup" 过程中的确切顺序放置这些操作。对于其他操作,我们取消选中默认操作。

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

  • info.ftl - 默认值为 here。单击欢迎电子邮件中的 link 后,用户最终会进入此模板生成的页面。此页面通常呈现显示各种通用信息消息的网页, 但它也呈现帐户设置过程的第一页和最后一页。所以我修改了它以检查 message.summary 是否匹配帐户设置过程的第一步或最后一步。如果这是第一步,我会在页面上呈现 'welcome' 文本。如果这是最后一步,我会渲染类似 'your account has been setup. Click here to login' 的内容。请参阅下面我如何修改 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 -->

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

  • terms.ftl - 显示条款和条件步骤
  • login-update-profile.ftl - 显示用户需要enter/update his/her全名
  • 的步骤
  • login-updated-password.ftl - 提示用户更改密码。

第五,当管理员创建新用户时,he/she触发向用户发送欢迎邮件: - 在 Keycloak 管理控制台中,一旦您 "Add" 成为新用户,请转到该用户的 "Credentials" 选项卡,然后在凭据重置 select 下执行 "Reset Actions" 下所需的帐户设置操作和然后点击 "Send email" 按钮。

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