Skip to content

Commit

Permalink
[Backport stable/8.5] fix: go client omit optional scope param if not…
Browse files Browse the repository at this point in the history
… set (#18156)

# Description
Backport of #18154 to `stable/8.5`.

relates to #16015
original author: @megglos
  • Loading branch information
megglos authored May 7, 2024
2 parents a1ca7e2 + 8d60b78 commit 6006965
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clients/go/pkg/zbc/oauthCredentialsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func NewOAuthCredentialsProvider(config *OAuthProviderConfig) (*OAuthCredentials
TokenConfig: &clientcredentials.Config{
ClientID: config.ClientID,
ClientSecret: config.ClientSecret,
Scopes: []string{config.Scope},
EndpointParams: map[string][]string{"audience": {config.Audience}},
TokenURL: config.AuthorizationServerURL,
AuthStyle: oauth2.AuthStyleInParams,
Expand All @@ -143,6 +142,10 @@ func NewOAuthCredentialsProvider(config *OAuthProviderConfig) (*OAuthCredentials
timeout: config.Timeout,
}

if config.Scope != "" {
provider.TokenConfig.Scopes = []string{config.Scope}
}

return &provider, nil
}

Expand Down
3 changes: 3 additions & 0 deletions clients/go/pkg/zbc/oauthCredentialsProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ func mockAuthorizationServerWithAudienceAndScope(t *testing.T, token *mutableTok

if scope != "" {
require.Equal(t, scope, query.Get("scope"))
} else {
// if the scope is empty the param should not be set at all
require.False(t, query.Has("scope"))
}

writer.Header().Set("Content-Type", "application/json")
Expand Down

0 comments on commit 6006965

Please sign in to comment.