Nerzal / gocloak

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

Create mapper for Client or Client Scopes #345

Closed ognjen-it closed 2 years ago

ognjen-it commented 2 years ago

Describe the bug We cannot create a mapper for Client or Client Scopes

To Reproduce Steps to reproduce the behavior:

var (
    ognjenGlobalName         = flag.String("ognjenGlobalName", "ognjen", "")
    ognjenClientProtocol     = flag.String("ognjenClientProtocol", "openid-connect", "")
    ognjenProtocolMapperName = flag.String("ognjenProtocolMapperName", "User Realm Role", "")
    ognjenGlobalOn           = flag.String("ognjenGlobalOn", "on", "")
)

func createClientScopeOgnjen() {

    ognjenClientScope := gocloak.ClientScope{
        Name:        ognjenGlobalName,
        Description: ognjenGlobalName,
        Protocol:    ognjenClientProtocol,
        ProtocolMappers: &[]gocloak.ProtocolMappers{
            {
                Name:           ognjenGlobalName,
                Protocol:       ognjenClientProtocol,
                ProtocolMapper: ognjenProtocolMapperName,
                ProtocolMappersConfig:  &gocloak.ProtocolMappersConfig{
                    UserinfoTokenClaim: ognjenGlobalOn,
                    IDTokenClaim:       ognjenGlobalOn,
                },
            },
        },
    }

    inf, err := client.CreateClientScope(ctx, token.AccessToken, *ognjenGlobalName, ognjenClientScope)
    if err != nil {
        fmt.Print(err.Error())
    } else {
        fmt.Print(inf)

    }
}

Expected behavior We want to create a Client Scope with a special mapper

Screenshots With the above code, we can create a Client Scope but a mapper has not been created.

image

Additional context Keycloak version is 16.1.1, it's deployed with helm on Kubernetes 1.21 I didn't find any example of how to do it :(

HimanshuM commented 2 years ago

@ognjen-it could you tell us why you closed this issue? I am facing the same issue, but could not find a solution in the package.

ognjen-it commented 2 years ago

because I don't think there are people here who are willing to help.. :( As you can see, you are the first one who post the comment here. Also, I asked in the Slack channel and noone answered me..

However, I will reopen it :)

HimanshuM commented 2 years ago

Thanks for your response @ognjen-it . I have created a PR for this issue https://github.com/Nerzal/gocloak/pull/351

ognjen-it commented 2 years ago

Wow, great to know that 🤗 Thank you for your effort to do that 🎉💯

I would like to know how to improve the gocloak, but I don't know the go language very well...

HimanshuM commented 2 years ago

Hey @ognjen-it the PR is now merged. Once a release is created, you could update the package and try it out. Thanks for your support :)

ognjen-it commented 2 years ago

Great! Thank you very much 🚀💯🥇 I will check it now and confirm if we can close this issue :)

Nerzal commented 2 years ago

V11.1.0 is released :)

I guess i can close this issue?

ognjen-it commented 2 years ago

Yes, you can :) Thank all!

chsavvaidis commented 2 years ago

@Nerzal @ognjen-it Hey, When I am trying to partial update the ProtocolMappers (e.g add a new one on an existing client scope), I am facing the same issue in both V11.1.0 and V11.2.0 :)

ognjen-it commented 2 years ago

Hi @chsavvaidis, @HimanshuM has resolved this problem with the PR #351. I'm not sure if I tested it, I have forgotten.

I need more time to check it because I deleted this piece of code..