I'm trying to add a Role to my realm in Keycloak but it's giving me a bad request response. My steps:
curl -X POST "http://localhost:8180/auth/realms/master/protocol/openid-connect/token" \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=admin&password=admin&grant_type=password&client_id=admin-cli'
curl -X GET http://localhost:8180/auth/admin/realms/my-realm/clients?clientId=my-client \
-H "Authorization: Bearer "$access_token \
-H 'cache-control: no-cache'
curl -v http://localhost:8180/auth/admin/realms/my-realm/clients/[ID-from-above]/roles \
-H "Content-Type: application.json" \
-H "Authorization: Bearer "$access_token --data '{"name":"test-role"}'
When I issue the last command I get a bad request response. What am I doing wrong? Thank you.
https://www.keycloak.org/docs-api/5.0/rest-api/index.html#_roles_resource
You seem to be pretty close.
I was able to make realm level roles by following REST API:
The difference between this and your call is that you are trying to make a client level role. Do you have a specific requirement for client level role or were you just trying out?
If Realm level roles fulfill your requirement, you can use above API.
Also check this post to make sure you have followed steps correctly to set up admin Rest API.