如何在密钥斗篷的自定义SPI中获取电子邮件验证链接

时间:2018-10-13 10:07:42

标签: java jboss redhat keycloak keycloak-services

我在下面有我的代码,它在我的notification-spi项目中,当创建新用户时会触发该代码。我能够收到电子邮件。但是,当在keycloak admin ui中创建帐户的管理员选择“ RequiredActions verify-email”时,我不知道如何获得电子邮件验证链接。

public void onEvent(AdminEvent adminEvent, boolean includeRepresentation) {


    EmailSenderProvider emailSender = session.getProvider(EmailSenderProvider.class);
    RealmModel realm = session.realms().getRealm(adminEvent.getRealmId());
    UserModel user = session.userCache().getUserById(adminEvent.getAuthDetails().getUserId(),
        realm);

    if (OperationType.CREATE.equals(adminEvent.getOperationType())) {
      LOGGER.info("OPERATION CREATE USER");
      LOGGER.info("Representation : " + adminEvent.getRepresentation());

      try {
        LOGGER.info("Sending email...");
        emailSender.send(realm.getSmtpConfig(), user, "Account Enrollment",
            "A new account has been created using your email.",
            "<h1>Account Enrollment</h1> <br/>"
                + "<p>A new account has been created using your email</p>");
        LOGGER.info("Email has been sent.");
      } catch (EmailException e) {
        LOGGER.info(e.getMessage());

      }
    }

  }

}

感谢您的帮助。

0 个答案:

没有答案