Nirmalya
Nirmalya

Reputation: 420

KeyCloak REST API: how to map a Role with a Group

I am using KeyCloak REST APIs and created a GROUP and a ROLE. Using REST API how to assign the ROLE to the Group? Here is the relevant APIs - KeyClaok API Guide

POST /admin/realms/{realm}/groups/{id}/role-mappings/realm

So question is how to use this API? Should I at first create the ROLE or this API itself will create the ROLE and do the mapping?

I tried in both the ways -

  1. Create the ROLE by POST, retrieve the RoleId from the response and send another POST to /admin/realms/{realm}/groups/{id}/role-mappings/realm by re-sending the same RoleRepresentation object with the created Id. Also I passed the GroupId with whom I want to map the Role. But I am getting error.
  2. In this case I didn't create the Role at the very beginning, but sent the RoleRepresentation object in the /admin/realms/{realm}/groups/{id}/role-mappings/realm API call. Again I am getting error.

The API guide is not clear on how to map the Group with the Role.

Any help will be highly appreciated.

Upvotes: 0

Views: 7073

Answers (1)

Apetrei Ionut
Apetrei Ionut

Reputation: 323

Request is good. For example I have this one:

http://localhost:5440/auth/admin/realms/{yourRealm}/groups/8129e7ed-db5f-423b-91f5-779b9d448d3b/role-mappings/realm

But you have to create the role first and send this RoleRepresentation in your BodyParameter. There is an array of RoleRepresentation.

For example my array of RoleRepresentation with one role:

[{"id":"16f77b0f-a03e-4995-a09f-dc02a0ee3f03","name":"rolle2","scopeParamRequired":false,"composite":false,"clientRole":false,"containerId":"yourRealm"}]

Upvotes: 1

Related Questions