我正在尝试实现自己的表单来更改用户的密码.我试图在Keycloak中找到用于更改用户密码的API,但我在文档中找不到任何内容.这样做有API吗?
Cha*_*ear 33
下面描述的解决方案将不再适用于 Keycloak 版本 12 或更高版本,因为开发人员决定删除所有帐户休息 API ,如本期所述。
感谢@Radivarig 指出这一点!
Keycloak 最近引入了此功能,但目前仍处于预览阶段,因此没有记录。
要使其工作,您需要account_api通过使用如下参数启动 keycloak来激活该功能-Dkeycloak.profile.feature.account_api=enabled:
bin/standalone.sh -Dkeycloak.profile.feature.account_api=enabled
Run Code Online (Sandbox Code Playgroud)
(来源:https : //www.keycloak.org/docs/latest/server_installation/index.html#profiles)
之后,您可以使用POST /auth/realms/your-realm/account/credentials/password并提供 http Header Accept: application/json。标头将使 keycloak 使用接受并返回 JSON 的 RestAPI-Service(而不是仅接受x-www-form-urlencoded并返回 HTML的基于表单的默认服务。)
作为Request-Body,提供这样的 JSON:
{
"currentPassword": "oldPassword",
"newPassword": "newPassword",
"confirmation": "newPassword"
}
Run Code Online (Sandbox Code Playgroud)
curl 的完整示例如下所示:
curl --request POST 'https://path-to-your-host.com/auth/realms/your-realm/account/credentials/password' \
--header 'Accept: application/json' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header 'Content-Type: application/json' \
--data-raw '{
"currentPassword": "oldPassword",
"newPassword": "newPassword",
"confirmation": "newPassword"
}'
Run Code Online (Sandbox Code Playgroud)
请注意 - 如上所述 - 此功能仍处于预览阶段,将来可能会发生变化。所以请谨慎使用!
Chr*_*ser 23
您可以使用 PUT /auth/admin/realms/{realm}/users/{id}/reset-password
这是s样本体.
{ "type": "password", "temporary": false, "value": "my-new-password" }
sho*_*ser 13
不是手动指定新密码,更好的安全措施是使用PUT /auth/admin/realms/{realm}/users/{id}/execute-actions-emailadmin调用"UPDATE_PASSWORD"作为必需的操作.这导致Keycloak向用户发送电子邮件,该电子邮件为用户提供了设置新密码的链接.
Meh*_*kri 10
正如Keycloak Admin REST API建议您可以发送PUT请求keycloakEndpoint/auth/{realm}/users/{id}/execute-actions-email以对用户执行操作。您需要按照此处所述获取管理员访问令牌
| 归档时间: |
|
| 查看次数: |
15941 次 |
| 最近记录: |