Skip to content

GoogleWebAuthorizationBroker.AuthorizeAsync doesn't support multiple scopes #1051

Closed
@bilal-fazlani

Description

@bilal-fazlani

This bug is about Google.Apis.Auth nuget package

private static UserCredential CreateCredential()
        {
            string[] scopes = { CalendarService.Scope.Calendar, GmailService.Scope.GmailReadonly};
            UserCredential credential;

            using (FileStream stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "userCredentials";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                
                Console.WriteLine("Credential file saved to: " + credPath);
            }
            return credential;
        }

This code is copied from google's help page here: https://developers.google.com/gmail/api/quickstart/dotnet

The only issue here is that, when I add other scopes to the array, it compiles & runs but only considers the first element of the array of scopes and the 2nd scope in array is ignore. When it opens the browser for the user to log in and allow the application to read or make changes, that screen only shows information about first scope in the array. In the example above, it will only ask for calendar permissions. This results in 403 status from google when it tries to perform gmail operations.

I have tried to switch the order of scopes in array and verified that it only works for 1st element of array.

Metadata

Metadata

Assignees

Labels

priority: p1Important issue which blocks shipping the next release. Will be fixed prior to 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