Nerzal / gocloak

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

Question/Help: Trying to get `Realm -> Clients -> Credentials -> Secret` #451

Closed dthisner closed 9 months ago

dthisner commented 9 months ago

I am trying to retrive a clients secret, when I am listing the clients, only one that is showing up is Dash, I am not seeing dash-backend and dash does not even exist in my client list in the dash realm.

Screenshot 2023-11-24 at 17 39 06

I am logged in as an admin for the Master realm. When I run:

clients, err := kc.Client.GetClients(kc.Ctx, kc.Token.AccessToken, "dash",
        gocloak.GetClientsParams{
            ClientID: &kc.Info.ClientID,
        },
    )
    if err != nil {
        return err
    }

I only get back 1 client, which is dash

what am I doing wrong? Any help is appreciated :)

dthisner commented 9 months ago

Clearly doing something wrong, looked at the example and used it:

    var clientList []*gocloak.Client

    // init map
    var clients = make(map[string]gocloak.Client)

    clientList, err := kc.Client.GetClients(kc.Ctx, kc.Token.AccessToken, "dash",
        gocloak.GetClientsParams{},
    )
    if err != nil {
        return err
    }

    for _, c := range clientList {
        fmt.Println(*c.ID)
        clients[*c.ClientID] = *c
    }

Now I am getting the correct values :)

dthisner commented 9 months ago

That did it, thanks :D