Hoping someone can help me on this. I've created my own Keycloak Realm, and client. I am using Spring boot and KeycloakRestTemplate from org.keycloak.adapters.springsecurity.client.KeycloakRestTemplate; to make all my calls.
I've been successful in adding client-level roles to the user role mapping to any given user.
I prefix my URI with /admin/realms/ when using the Keycloak API docs. So far all my requests have worked (getting a list of users from my client, getting a list of users that have a particular client-level role, and even adding client-level roles to a user as described above)
My problem is I cannot delete client-level roles from a user. I've looked at the keycloak docs and it looks like I've followed everything correctly. I also made sure the user had applicable client roles available to be deleted. I really appreciate any comments or help given!!
https://www.keycloak.org/docs-api/14.0/rest-api/index.html
"Delete client-level roles from user role mapping DELETE /{realm}/users/{id}/role-mappings/clients/{client}"
import org.keycloak.adapters.springsecurity.client.KeycloakRestTemplate;
.
.
.
@Autowired
private KeycloakRestTemplate restTemplate;
.
.
.
.
.
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(keycloakServerUrl + "/admin/realms/"+keycloakRealm+"/users/"+userId+"/role-mappings/clients/"+keycloakClientId);
this.restTemplate.postForEntity(builder.toUriString(), rolesList, List.class); // this works! Note: rolesList is an List<RoleRepresentation> object
.
.
.
this.restTemplate.delete(builder.toUriString(), rolesList); // Does not work!
URI: http://XXXXXXXXXXXXXXX:8180/auth/admin/realms/VLS/users/2144cc43-59f4-4406-9527-2a59ee0c3751/role-mappings/clients/53e659e1-7cef-4dbb-8cdd-b786ca3a44a4
Error when calling Delete API: org.springframework.web.client.HttpClientErrorException$UnsupportedMediaType: 415 Unsupported Media Type: [{"error":"RESTEASY003065: Cannot consume content type"}]
Edit 1: I have also given myself ALL available roles from all clients as a precaution beforehand. I understand some roles are needed to perform certain tasks even through the API. I've taken this into account.