无法使用 Keycloak admin api 设置用户凭据

Posted

技术标签:

【中文标题】无法使用 Keycloak admin api 设置用户凭据【英文标题】:Unable to set user credential using Keycloak admin api 【发布时间】:2017-05-26 21:20:39 【问题描述】:

我们正在使用 Java 代码将用户导入 KeyCloak,并且我们正在使用 keycloak-admin-client API。

尝试如下设置密码,但不是为用户设置/保留密码。

 CredentialRepresentation credential = new CredentialRepresentation();
    credential.setType(CredentialRepresentation.PASSWORD);
    credential.setValue("password");
    userRepresentation.setCredentials(Arrays.asList(credential));

还有其他方法可以设置用户凭据

【问题讨论】:

【参考方案1】:

我使用以下端点来设置凭据

UserResource userResource = keycloak.realm(realm).users().get(userId);
CredentialRepresentation credential = new CredentialRepresentation();
    credential.setType(CredentialRepresentation.PASSWORD);
    credential.setValue(password);
    credential.setTemporary(false);
    userResource.resetPassword(credential);

【讨论】:

以上是关于无法使用 Keycloak admin api 设置用户凭据的主要内容,如果未能解决你的问题,请参考以下文章