Keycloak-6.0.1 自定义认证器SPI

Keycloak-6.0.1 Custom Authenticator SPI

我正在尝试实现自定义 keycloack Authenticator SPI 以针对外部 Datasource/Rest 服务进行身份验证。计划是将它们迁移到 keycloak 中。

Updated the browser flow(copy and created a new flow and bind it).

First time when the user logs in, will display custom theme login screen.

On submit Using Custom SPI authenticate against external service.

On success create users on the keycloak datasource.

Create custom mappers to add extra user attributes on tokens.

我正在关注官方指南的第 8.3 节 https://www.keycloak.org/docs/latest/server_development/index.html#_auth_spi_walkthrough,这与我需要的非常相似。

此外,遵循示例(https://github.com/keycloak/keycloak/tree/master/examples/providers/authenticator) 我认为说明并未将其映射到新版本。

例如: 在您的副本中,单击 "Actions" 菜单项和 "Add Execution"。选择秘密问题。

In Keycloak-6.0.1, there isn't any such execution as "Pick Secret Question". I really don't need this, but I was atleast trying to set this flow to get hold on how the flow works.

接下来您必须注册您创建的所需操作。单击 Authenticaiton 菜单中的 Required Actions 选项卡。单击“注册”按钮并选择新的所需操作。

There isn't such Register button on the required action.

我做过的事情。 创造了新领域 已注册 UI 客户 在 keycloak 表的新领域中创建新用户。 UI 登录重定向到 Keycloak UI 并成功通过身份验证并能够使用 javascript 适配器

成功检索令牌
componentDidMount = () => {
        const keycloak = Keycloak('/keycloak.json');
        keycloak.init({onLoad: 'login-required'}).then(authenticated => {
            this.setState({ keycloak: keycloak, authenticated: authenticated })
        })
    }

....
....

if(this.state.keycloak) {
            if(this.state.authenticated) return (
                <div className="contact-body">
                 <p>Name: {this.state.name}</p>
                 <p>Email: {this.state.email}</p>
                 <p>ID: {this.state.id}</p>
               </div>
              );
      }
}

想要使用 Keycloak 登录 UI 功能(如 OTP)以及自定义身份验证器 SPI。在自定义身份验证器 SPI 中获取用户名和密码等表单字段,并使用外部服务对其进行身份验证。然后在Keycloak DB中创建用户。

管理员可以 lock/temporarily 在 keycloak 中暂停某个领域内的用户吗?

我打算使用的另一个选项是,将 login.ftl onsubmit 更新为 post username/password 以使用 keycloak url 作为查询参数传递给自定义服务。
将根据自定义服务验证它,在 keycloak 数据库上创建用户并重定向到通过查询参数传递的 keycloak url。这似乎不是正确的方法。

任何 help/thoughts 都会非常有帮助。

这是您实施的错误 SPI。 对于外部数据源或服务集成,您必须实施自定义 User Storage SPI.

你应该使用 "User Storage SPI"。 Keycloak Doc

第 11 节

第 8 部分,如果您需要 extra/custom 身份验证,如秘密问题,则需要。