I created users and roles from keycloak, but when I tried to export it I couldn't find any user or roles in realm.json
how can I export json realm including users and roles from keycloak?
Thanks
I created users and roles from keycloak, but when I tried to export it I couldn't find any user or roles in realm.json
how can I export json realm including users and roles from keycloak?
Thanks
You will not be able to do that using the export functionality. However, you can get that information by using Keycloak Admin REST API
The first step is to get an access token from the admin a-like user (e.g., the admin of the master realm), so that you can call the Rest API:
curl -d "client_id=admin-cli" \
-d "username=$ADMIN_NAME" \
-d "password=$ADMIN_PASSWORD" \
-d "grant_type=password" \
https://$KEYCLOAK_IP/auth/realms/master/protocol/openid-connect/token
You will get a JSON response with the admin token. Extract the access token from that response (lets called $ACCESS_TOKEN).
Now you can get the list of users:
curl -X GET https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/users
-H "Content-Type: application/json" \
-H "Authorization: bearer $ACCESS_TOKEN"
Now to get the Realm Roles :
curl -X GET https://$KEYCLOAK_IP/auth/admin/realms/$REALM_NAME/roles
-H "Content-Type: application/json" \
-H "Authorization: bearer $ACCESS_TOKEN"
Now you just need to save the JSON responses from those endpoint into JSON files.