问题描述:

After successfully creating a user by Admin Rest API in Keycloak (2.4.0.Final) I can not log in using this user. I can only enter the administration console and reset the user's password.

Follow the code used.

 Keycloak keycloak = Keycloak.getInstance(

"http://localhost:8080/auth",

"master",

"admin",

"admin",

"admin-cli");

CredentialRepresentation credential = new CredentialRepresentation();

credential.setType(CredentialRepresentation.PASSWORD);

credential.setValue("12345678");

credential.setTemporary(false);

UserRepresentation user = new UserRepresentation();

user.setUsername("testBackend");

user.setFirstName("testBackend");

user.setLastName("testBackend");

user.setEmail("[email protected]");

user.setEnabled(true);

user.setCredentials(Arrays.asList(credential));

keycloak.realm("realm-test").users().create(user);

网友答案:

keycloak does not support the create user(API) with password, u need to make another call to register the password for this user:

UserResource userResource=kc.realm("master").users().get(id);
CredentialRepresentation newCredential = new CredentialRepresentation();
newCredential.setType(PASSWORD);
newCredential.setValue("Tersting1");
newCredential.setTemporary(false);
userResource.resetPassword(newCredential);`
相关阅读:
Top