Keycloak: Add a custom attribute to all existing users

Viewed 731

I already have a running keycloak instance with a lot registered users. How can I add a new custom attribute (with an empty value) to all users without doing it manually?

Thanks in advance.

1 Answers

How can I add a new custom attribute (with an empty value) to all users without doing it manually?

You can use Keycloak Rest Admin API:

First you use endpoint

GET /{realm}/users

to get all the users. Then for each user you extract its ID an call the endpoint :

PUT /{realm}/users/{id}

with the payload {"attributes": <old Attributes> + < new Attributes>}

I have create a bash script for this in my repo. Running example:

sh addAttributeToAllUsers.sh localhost:8080 admin admin test '{"c":["c"]}'
Related