Skip to content

Specifying option.WithScopes is ignored when using option.WithTokenSource #1644

@salrashid123

Description

@salrashid123

If you use both

at the same time as shown below, the scopes settings from the tokensource is used.

The following works for cloudidentity api because the "books" api scope is simply ignored

    configci, err := google.JWTConfigFromJSON(serviceAccountJSON, cloudidentity.CloudPlatformScope, cloudidentity.CloudIdentityGroupsReadonlyScope)

    tsci := configci.TokenSource(ctx)

    cisvc, err := cloudidentity.NewService(ctx, option.WithTokenSource(tsci), option.WithScopes("https://www.googleapis.com/auth/books"))

but if you invert it, you'll see a scopes error since the actual token from the config is used

    configci, err := google.JWTConfigFromJSON(serviceAccountJSON, "https://www.googleapis.com/auth/books")
    tsci := configci.TokenSource(ctx)

    cisvc, err := cloudidentity.NewService(ctx, option.WithTokenSource(tsci), option.WithScopes(cloudidentity.CloudPlatformScope, cloudidentity.CloudIdentityGroupsReadonlyScope))

consider throwing an error if both are set


$ go version
go version go1.17.1 linux/amd64
module main

go 1.17

require (
	golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c
	google.golang.org/api v0.91.0
)

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions