From 7b1503f561fde71a03183a7ef761ecb0f8bc9d9c Mon Sep 17 00:00:00 2001 From: Nerzal Date: Wed, 24 May 2023 15:32:51 +0200 Subject: [PATCH] Add optional scope(s) to LoginClient function (#424) Co-authored-by: Tobias Theel --- client.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 119722d1..1a94c3d7 100644 --- a/client.go +++ b/client.go @@ -550,12 +550,18 @@ func (g *GoCloak) LoginAdmin(ctx context.Context, username, password, realm stri } // LoginClient performs a login with client credentials -func (g *GoCloak) LoginClient(ctx context.Context, clientID, clientSecret, realm string) (*JWT, error) { - return g.GetToken(ctx, realm, TokenOptions{ +func (g *GoCloak) LoginClient(ctx context.Context, clientID, clientSecret, realm string, scopes ...string) (*JWT, error) { + opts := TokenOptions{ ClientID: &clientID, ClientSecret: &clientSecret, GrantType: StringP("client_credentials"), - }) + } + + if len(scopes) > 0 { + opts.Scope = &scopes[0] + } + + return g.GetToken(ctx, realm, opts) } // LoginClientTokenExchange will exchange the presented token for a user's token