简体   繁体   English

Keycloak:在AngularJS应用程序中更新用户密码

[英]Keycloak: Update user password in AngularJS application

I'm building an AngularJS application protected by Keycloak. 我正在构建一个受Keycloak保护的AngularJS应用程序。 Each user should update his password within his user profile. 每个用户都应在其用户配置文件中更新其密码。

Calling the Keycloak API for password 调用Keycloak API以获得密码

GET /auth/realms/{realm_name}/account/password GET / auth / realms / {realm_name} /帐户/密码

returns HTML content from Keycloak. 从Keycloak返回HTML内容。 I would like to build my own form to update a user's password. 我想建立自己的表单来更新用户密码。

In the Keycloak documentation I found 在Keycloak文档中,我发现

POST /auth/realms/{realm_name}/account/password POST / auth / realms / {realm_name} /帐户/密码

which requires the attributes 这需要属性

{
    'password' => user's current password
    'password-new' => new password
    'password-confirm' => new password again
    'stateChecker' => token from keycloak
}

Calling 调用

POST /auth/realms/{realm_name}/account/password POST / auth / realms / {realm_name} /帐户/密码

without the 'stateChecker' attribute causes an error. 如果没有'stateChecker'属性,则会导致错误。 This attribute is needed. 此属性是必需的。

So here are my questions: 所以这是我的问题:

  • How do I get the value for stateChecker from keycloak for the logged in user (in Keycloak it's in a hidden input field)? 如何从已登录用户的stateChecker获取stateChecker的值(在Keycloak中,它在隐藏的输入字段中)?
  • Is there another possibility to change a user's password with a REST API call? 是否可以通过REST API调用更改用户密码?

Thanks in advance. 提前致谢。

Note: 注意:

Calling: 呼叫:

POST /auth/realms/{realm_name}/account/password POST / auth / realms / {realm_name} /帐户/密码

with hard coded attributes and values 具有硬编码的属性和值

{
    'password': 'somepasswd',
    'password-new': 'someNEWpasswd',
    'password-confirm': 'someNEWpasswd',
    'stateChecker': '<token copied and pasted from keycloak>',
}

is working! 正在工作!

My advice would be to overwrite the keycloak theme (check this out: http://docs.jboss.org/keycloak/docs/1.2.0.Beta1/userguide/html/themes.html ). 我的建议是覆盖keycloak主题(请参阅: http ://docs.jboss.org/keycloak/docs/1.2.0.Beta1/userguide/html/themes.html)。

You can extend and modify the existing forms to look like the rest of your application. 您可以扩展和修改现有表单,使其看起来像应用程序的其余部分。

Finally I ended up with an own implementation of a rest endpoint using keycloaks admin rest api. 最后,我最终使用keycloaks admin rest api对rest端点进行了自己的实现。

Building an own theme could be a solution too, as Lisa stated. 正如Lisa所说,建立自己的主题也是一种解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM