I have created custom protocol mapper with mapper type "hardcoded claim". Can I set "Claim value" field using keycloak API? I learned API specification and did not found anything. Is there a working example? I am using Springboot restAPI and Keycloak.
For that you can use the endpoint Update the mapper :
PUT /{realm}/clients/<ID_OF_CLIENT>/protocol-mappers/models/<ROLE_MAPPER_ID>
for example
curl -X PUT http://$KEYCLOAK_IP/auth/admin/realms/<REALM_NAME>/clients/<ID_OF_CLIENT>/protocol-mappers/models/<MAPPER_ID>
With the payload being the new updated configuration of your Mapper, for instance:
{"id":"<MAPPER_ID>","name":"Hardcore","protocol":"openid-connect","protocolMapper":"oidc-hardcoded-claim-mapper","consentRequired":false,"config":{"claim.value":"<NEW_HARDCODE_VALUE>","userinfo.token.claim":"true","id.token.claim":"true","access.token.claim":"true","claim.name":"Name","jsonType.label":"String"}}
The ID
of Client you can get it via the Admin Console, by going to:
Realm
;The mapper ID
you can get it via the Admin console, by going to:
Realm
;You can get both the ID
of the Client and the Mapper by using this endpoint:
http://$KEYCLOAK_IP/auth/admin/realms/<REALM_NAME>/clients?clientId=<CLIENT_ID>
Extract from the JSON
response that you will get the Client and Mapper IDs.