Nerzal / gocloak

golang keycloak client
Apache License 2.0
1.01k stars 275 forks source link

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

Closed LvHW1997 closed 6 months ago

LvHW1997 commented 6 months ago

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

osmian commented 6 months ago

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

LvHW1997 commented 6 months ago

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)

osmian commented 6 months ago

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,

LvHW1997 commented 6 months ago

Okay, Thanks for your reply.