I'm trying to do OAuth2 using Azure hosted web apps, and I can't use service accounts (there is a number of solutions available here, but they all stick to service accounts/certs), while I need the user to authenticate and authorize by Google.
Code:
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets { ClientId = _clientId, ClientSecret = _clientSecret },
scopes,
User.Identity.Name,
CancellationToken.None,
new FileDataStore("GA.Auth.Store")) /* tried this to be null as well */
.Result;
var service = new AnalyticsService(
new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Analytics API Sample"
});
It works locally but gives this exception when deployed as an Azure web app:
[HttpListenerException (0x5): Access is denied]
Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +82
Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) +76
Google.Apis.Auth.OAuth2.<AuthorizeAsync>d__1.MoveNext() +233
I am guessing that GoogleWebAuthorizationBroker.AuthorizeAsync is trying to establish an http listener which is not (?) possible within Azure web apps.
I tried using Azure web apps authentication. This does authenticate user, but how can I retrieve the authenticated user to authorize him against Google?
BTW: Because I need GA Real-Time, I am stuck with GA Reporting v3 library.