Skip to content

Commit

Permalink
Add optional scope(s) to LoginClient function (#424)
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Theel <[email protected]>
  • Loading branch information
Nerzal and Tobias Theel authored May 24, 2023
1 parent f054fd2 commit 7b1503f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7b1503f

Please sign in to comment.