Skip to content

Commit

Permalink
fix(option): Having both a TokenSource and Scopes should fail validation
Browse files Browse the repository at this point in the history
If both ds.TokenSource and ds.Scopes are set, then an error will be returned as Scopes will be ignored

Fixes googleapis#1644
  • Loading branch information
eisandbar committed Aug 16, 2022
1 parent 55f563d commit 4aa9b44
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/settings.go
Expand Up @@ -107,6 +107,9 @@ func (ds *DialSettings) Validate() error {
if len(ds.Scopes) > 0 && len(ds.Audiences) > 0 {
return errors.New("WithScopes is incompatible with WithAudience")
}
if len(ds.Scopes) > 0 && ds.TokenSource != nil {
return errors.New("WithScopes is incompatible with WithTokenSource")
}
// Accept only one form of credentials, except we allow TokenSource and CredentialsFile for backwards compatibility.
if nCreds > 1 && !(nCreds == 2 && ds.TokenSource != nil && ds.CredentialsFile != "") {
return errors.New("multiple credential options provided")
Expand Down

0 comments on commit 4aa9b44

Please sign in to comment.