使用GoogleWebAuthorizationBroker.AuthorizeAsync的HttpListenerException“访问被拒绝”

时间:2016-07-25 06:15:43

标签: c# azure azure-web-sites google-analytics-api google-api-client

我正在尝试使用Azure托管的网络应用程序来执行OAuth2,我不能使用服务帐户(这里有许多解决方案,但它们都坚持服务帐户/证书),而我需要用户通过Google进行身份验证和授权。

代码:

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"
    });

它在本地运行,但在部署为Azure Web应用程序时会出现此异常:

[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

我猜测 GoogleWebAuthorizationBroker.AuthorizeAsync 正在尝试在Azure网络应用中建立一个不可能(?)的http侦听器。

我尝试使用Azure网络应用验证。这会对用户进行身份验证,但如何检索经过身份验证的用户以授权他对抗Google?

BTW:因为我需要GA Real-Time,所以我坚持使用GA Reporting v3库。

0 个答案:

没有答案
相关问题