Keycloak 自定义身份验证器脚本问题:无法在单击按钮时从用户名表单切换到密码表单

问题描述

我在 Keycloak 上编写了一个自定义身份验证器脚本,该脚本在单击用户名表单上的登录按钮时触发。脚本检查输入的用户名是否以“@abc.com”结尾,如果是,则将用户重定向到为此域配置的外部 IDP,如果不是,则应打开密码表单供用户使用凭据进行身份验证。 基于域的 IDP 发现和相应的重定向工作正常,但另一种情况,即当输入的用户名与任何指定的域不匹配时,我需要将用户重定向到密码表单。但在这里我收到以下附加错误。 (输入的用户名和密码经过验证并存在于 keycloak 本地数据库中)

enter image description here

自定义验证器脚本如下:

`function authenticate(context) {
  LOG.info("inside custom authenticator" + context);
  var username = user ? user.username : "anonymous";
  LOG.info(script.name + " --> trace auth for: " + username);
  if (username.endsWith("@abc.com")) {
    redirect_to_idp(context,"ABC-IDP");
    return;
  }
  var response = context
    .form()
    .setAttribute("userId",username)
    .createForm("login-password.ftl");
  context.challenge(response);
  return;
}`

似乎在 username-form 中输入的用户名没有保留用于密码表单来验证用户。 请验证我是否以正确的方式处理用例以及如何解决此问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)