Nerzal / gocloak

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

Question: How to set Scopes in the Realm? #316

Closed shibumi closed 2 years ago

shibumi commented 3 years ago

Hello,

How would I set these Scopes via the RealmRepresentation?

https://kurisu.shibumi.dev/share/img-2021-10-29-13-58-42.png

shibumi commented 3 years ago

I could find the "FullScopeAllowed" variable in the Client Object, but I am still looking for a way to assign realm Roles and client Roles to a Client Scope.

I have to admit I am a little bit confused, because there are "Clients->Scopes" and "ClientScopes".

shibumi commented 2 years ago

I tried setting the clientscope via filling the slice of interfaces with roles:

        var scopeMappings []interface{}
        for _, scopeMapping := range *r.ScopeMappings {
            scopeMappings = append(scopeMappings, gocloak.Role{
                Name:               scopeMapping.name,
                Composite:          scopeMapping.Composite,
                ClientRole:         scopeMapping.ClientRole,
            })
        }

and then using this as: scopeMappings: &scopeMappings, but this just produces an API error. There is no documentation for setting the Scopes. Any help? :(

Nerzal commented 2 years ago

Hi,

i guess the best solution is to check how the Keycloak frontend sets scopes, by doing it manually while checking DevTools in the browser. That may give a hint, what we are doing wrong

shibumi commented 2 years ago

I fixed this. Instead of trying to writing the mappings directly into the realm I simply called these two methods here:

CreateClientScopeMappingsRealmRoles() CreateClientScopeMappingsClientRoles()