Nerzal / gocloak

golang keycloak client
Apache License 2.0
1.03k stars 283 forks source link

Expose the `briefRepresentation` query parameter #306

Closed HarikrishnanBalagopal closed 2 years ago

HarikrishnanBalagopal commented 3 years ago

Is your feature request related to a problem? Please describe. See https://github.com/Nerzal/gocloak/issues/216

Describe the solution you'd like Change the function signature of GetCompositeClientRolesByUserID and other similar functions to allow setting the query parameter.

Describe alternatives you've considered Could possibly add a way to specify this and other common query parameters when constructing a new client

func NewClient(basePath string, options ...func(*gocloak)) GoCloak {

Additional context The java library already exposes the query parameter: https://stackoverflow.com/questions/63116643/keycloak-can-not-get-attributes-of-a-role

Nerzal commented 3 years ago

Is this query param available for more than one request?

HarikrishnanBalagopal commented 3 years ago

@Nerzal yes, searching around for briefRepresentation in https://www.keycloak.org/docs-api/15.0/rest-api/index.html gives 16 endpoints:

GET /{realm}/groups/{id}/role-mappings/clients/{client}/composite
GET /{realm}/users/{id}/role-mappings/clients/{client}/composite
GET /{realm}/groups
GET /{realm}/groups/{id}/members
GET /{realm}/groups/{id}/role-mappings/realm/composite
GET /{realm}/users/{id}/role-mappings/realm/composite
GET /{realm}/clients/{id}/roles
GET /{realm}/clients/{id}/roles/{role-name}/groups
GET /{realm}/roles
GET /{realm}/roles/{role-name}/groups
GET /{realm}/client-scopes/{id}/scope-mappings/clients/{client}/composite
GET /{realm}/client-scopes/{id}/scope-mappings/realm/composite
GET /{realm}/clients/{id}/scope-mappings/clients/{client}/composite
GET /{realm}/clients/{id}/scope-mappings/realm/composite
GET /{realm}/users
GET /{realm}/users/{id}/groups
Nerzal commented 3 years ago

Okay so for the solution it feels like being able to control this param per request feels more natural. Are you aware of any similar params, that we might not have implemented yet?

We might want to add an optional parameter to these functions and hand in a param struct/map/whatever, which could contain all of these params, that we know

HarikrishnanBalagopal commented 3 years ago

Another solution is to add a functional option that allows the user to set a custom resty client when constructing a gocloak client. This way the user can set a custom resty client that manipulates the request before it is sent out.

This is a more generic solution but it may not be the most user friendly.

Nerzal commented 3 years ago

That is already possible, as that function returns a pointer.

func (client *gocloak) RestyClient() *resty.Client { return client.restyClient }

But that is a too complicated usecase for a feature, that feels like it should be "natively" supported by this library.

HarikrishnanBalagopal commented 3 years ago
Are you aware of any similar params, that we might not have implemented yet?

There are some endpoints like POST /{realm}/user-storage/{parentId}/mappers/{id}/sync which aren't exposed by this library. It takes a direction query parameter. Other than that I am not sure.

HarikrishnanBalagopal commented 3 years ago
That is already possible, as that function returns a pointer.

Oh nice!

But that is a too complicated usecase for a feature, that feels like it should be "natively" supported by this library.

Yes for this issue it would be too complicated, but being able to set a custom resty client can be useful. Usecases:

HarikrishnanBalagopal commented 2 years ago

@Nerzal has this issue been fixed by commit ae82f6cd6f24e28502a100cc3099ef1b8af421e6 ?

https://github.com/Nerzal/gocloak/commit/ae82f6cd6f24e28502a100cc3099ef1b8af421e6#diff-4b667feae66c9d46b21b9ecc19e8958cf4472d162ce0a47ac3e8386af8bbd8cfR1414 https://github.com/Nerzal/gocloak/commit/ae82f6cd6f24e28502a100cc3099ef1b8af421e6#diff-72487d6e423e37c0af7994baddca95c1e2acc7e7ca51b8d13d03caa8e4485a16R348

Made by PRs: https://github.com/Nerzal/gocloak/pull/285 https://github.com/Nerzal/gocloak/pull/314

I made this issue while this library was on v8. It seems in v10 the signature was changed and the function now takes a struct to allow additional query parameters:

    roleInfos, err := common.AuthServerClient.GetClientRoles(context.TODO(), accessToken, realm, clientIdNotClientId, gocloak.GetRoleParams{BriefRepresentation: &brief})

This allows to return non-brief representation including role attributes.

Nerzal commented 2 years ago

at first glance it looks like we have fixed the issues.