GoogleWebAuthorizationBroker.AuthorizeAsync doesn't support multiple scopes
See original GitHub issueThis 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:
- Created 6 years ago
- Comments:18
Top GitHub Comments
@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…
Great 😃 No problem.