question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GoogleWebAuthorizationBroker.AuthorizeAsync doesn't support multiple scopes

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18

github_iconTop GitHub Comments

1reaction
chrisdunelmcommented, Sep 29, 2017

@slimCODE Thanks for the code, I’ve reproduced the problem in a .NET Core 1.1 console app. The problem does not occur in a Windows desktop console app. I’ll investigate…

0reactions
chrisdunelmcommented, Oct 3, 2017

Great 😃 No problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Google API authorisation with ...
GoogleWebAuthorizationBroker.AuthorizeAsync uses fileDatastore by default it stores the user credentials in the machines %appdata% folder.
Read more >
Class GoogleWebAuthorizationBroker (1.60.0) | .NET client ...
The reason that this is not 'private const' is that a user can change it and store the credentials in a different location....
Read more >
Authorize Requests | Campaign Manager 360
To request access using OAuth 2.0, your application needs the scope information, as well as information that Google supplies when you register ...
Read more >
OAuth 2.0 for Google Regular Accounts (installed ...
Request authorization from Google to access the scopes of Gmail and the e-mail address (areas of authorization are called scopes). Do the authorization...
Read more >
GoogleWebAuthorizationBroker.AuthorizeAsync - not open ...
I have a problem in the permit application for authentication. My application runs on IIS7 (framework 4.0). Code: string[] scopes = new string[] ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found