Search code examples
passwordsmigrationstorekeycloak

Store password in Keycloak


I have created a custom user storage provider which will migrate users from legacy system to keycloak's local storage on demand basis.

All the details of the migrated user is being stored in Keycloak except password.

userModel.setEmail(email);
userModel.setEnabled(isEnabled);
userModel.setEmailVerified(isEmailVerified);
userModel.setFirstName(firstName);
userModel.setLastName(lastName);

I am using the above code to store all the information of the user, but I didn't find any method/class in which stores the password.

Can anyone please help me with it?

P.S. I am using Keycloak-3.3.0-Final version.


Solution

  • You can use

    session.userCredentialManager().updateCredential(realm, user, UserCredentialModel.password(passwordNew, false));
    

    where session is the current KeycloakSession which you have access to in your custom user storage provider.