Nerzal / gocloak

golang keycloak client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does CreateClientRole not return information corresponding to the role, especially the ID

LvHW1997 opened this issue · comments

Is your feature request related to a problem? Please describe.
When creating a client role, the interface only returns the name of the role
However, when creating role policies or adding roles to users, it is necessary to have the ID of the role, which results in the need to traverse all roles to obtain the corresponding role ID

Describe the solution you'd like
When creating a character, directly return the character's information or ID

Describe alternatives you've considered
When creating a character, directly return the character's information or ID, or add an interface to obtain the character ID through the character name

commented

When creating a client role, I believe it does return the ID right?

Through testing, I found that only the name of the role is returned, not its ID

`func TestCreateRole(t *testing.T) {
...

role, err := client.Client.CreateClientRole(ctx, clientToken.AccessToken, Realm, idOfClient, gocloak.Role{
	Name: gocloak.StringP("just_for_test"),
})
if err != nil {
	t.Fatalf("create role error: %v", err)
}
t.Logf("role: %v", role)

}`
=== RUN TestCreateRole
login_test.go:48: role: just_for_test
--- PASS: TestCreateRole (0.07s)

commented

I see that as well, I dont think this is something that can be changed in the gocloak repository though since it uses the response header of "Location" to parse out that id which is returned.

If you look at the response headers it is parsing out the "just_for_test"

Location -> [http://localhost:8080/admin/realms/gocloak/clients/CLIENT_ID/roles/just_for_test

So this is returned from keycloak which isnt controlled by the code here,

Okay, Thanks for your reply.