I want to set one temporary password for a list of specific users (Not all users, just a specific list of an organization) And this temporary password, the user can change on their next logon.
Is there a way for me to do that performing a Backend Call to Keycloack's Admin API?
I guesss one alternative would be to set this list of users to change password on next logon, can I do that setting a value in a column of a specific Table on KC's Database?
I looked up into Keycloack's Docs and there is the
PUT /admin/realms/{realm}/users/{id}/reset-password
But I think that this method only accepts one user at a time.
You have the ability to change the passwords of users by repeatedly using the
PUT APImethod.Each call to the PUT API is dedicated to resetting the password for a single user.
This process can be repeated as needed for multiple users.
You are capable of performing this operation for a large number of users, up to a couple of thousand.
The implication is that the API and your system can handle a significant volume of reset password requests without issues.
Demo steps
The goal is to generate 50 users using a
Node.jsscript. Each user will have a unique set of credentials like username, password, and email.For these users, a specific pattern is followed regarding password resetting: Users positioned at odd rows (like the 1st, 3rd, 5th, etc.) will have their passwords marked for a temporary reset. In contrast, users at even rows (2nd, 4th, 6th, etc.) will not require an immediate password reset.
But that order will broken due to sort by
usernameAfter generating these users, the next step is to create their profiles in Keycloak, which is an identity and access management service. This involves populating Keycloak with the user data generated by the Node.js script.
Finally, for users who have the reset flag set to true (those in even rows), their passwords will be reset in Keycloak. This action is likely managed through a specific API call to Keycloak for each user needing a password reset.
This process ensures a systematic creation and management of user accounts, with password reset policies applied selectively based on the user's position in the list.
Step 1: Create Users save User.xlsx
Install Dependencies for
node.jsSave as
save_excel.jsMore detail information in hereRun it
Result, open "Users.xlsx" file by Excel
"All the username, password, and email fields should be in lowercase, except for the 'First Name' and 'Last Name' fields, where the first letter of each name should be capitalized."
Step 2: Create Users to Keycloak
Launching Keycloak by Docker Compose in here
"You will need to increase the duration of the Master Token's validity, which by default is set to 1 minute. Additionally, the realm named 'my-realm' must be created manually."
Save as
create_users.jsRun it
Result
Step 3: Reset Password only true flag users
Example
But won't reset this user
Save as
reset_password_users.jsRun it
Result
Try login
Will show ask to new password
But 2nd row user no problem to login