Is there any API to pass values to update a keycloak realm's json after the realm is created ?
I am trying to pass a value to a realm dynamically.
Is there any API to pass values to update a keycloak realm's json after the realm is created ?
I am trying to pass a value to a realm dynamically.
Is there any API to pass values to update a keycloak realm's json after the realm is created ?
Yes, you can find that, and several other endpoints, in the Keycloak Admin Rest API documentation.
To update the realm you can use the endpoint PUT /{realm}.
Update: The /auth
path was removed starting with Keycloak 17 Quarkus distribution. So you might need to remove the /auth
from the endpoint calls presented on this answer.
You can get that information using the Keycloak Admin REST API; to call that API, you need an access token from a user with the proper permissions. I will be using the admin
user from the master
realm.
curl “https://${KEYCLOAK_HOST}/auth/realms/master/protocol/openid-connect/token” \
-d "client_id=admin-cli" \
-d "username=${ADMIN_NAME}” \
-d "password=${ADMIN_PASSWORD}" \
-d "grant_type=password"
You get a JSON response with the admin's token. Extract the value of property access_token
from that response. Let us save it in the variable $ACCESS_TOKEN
for later reference.
To change the realm you can call the following:
curl -X PUT “https://${KEYCLOAK_HOST}/auth/admin/realms/${REALM_NAME}” \
-H "Content-Type: application/json" \
-H "Authorization: bearer ${ACCESS_TOKEN}” \
-d "${THE_REALM_JSON}"
The ${THE_REALM_JSON}
will contain the new values that you want to change in the realm.