Unable to set user credential using Keycloak admin api
Asked Answered
D

1

6

We are importing users to KeyCloak using Java code, and we are using keycloak-admin-client API.

Tried Setting password as follows , but it is not setting/persisting the password for the user.

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

Is there other way to set user credentials

Disdain answered 11/1, 2017 at 22:23 Comment(0)
D
8

I used following Endpoint to set the Credentials

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);
Disdain answered 15/1, 2017 at 23:16 Comment(1)
An obvious doubt...why can't we use userRepresentation.setCredentials() method to set the password?Christology

© 2022 - 2024 — McMap. All rights reserved.