【问题标题】:Google Auth runs in Visual studio but hangs when deployed to IISGoogle Auth 在 Visual Studio 中运行,但在部署到 IIS 时挂起
【发布时间】:2017-03-28 08:11:00
【问题描述】:

我正在使用Google .Net client library。它的工作方式是当用户想要向 Google 进行身份验证时,库会生成一个新网页供用户进行身份验证。

System.Diagnostics.Process.Start(authorizationUrl);

我使用库的代码

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    scopes,
    userName,
    CancellationToken.None).Result;

如果我通过 Visual Studio 在本地运行它,它工作正常。但是,如果我尝试部署它就会挂起。如果使用本地 IIS 使用 Visual Studio 运行它。我收到以下错误。

System.Exception: CreateServiceAccountAnalyticsReportingFailed ---> System.AggregateException:发生一个或多个错误。 ---> System.ComponentModel.Win32Exception:访问被拒绝 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) 在 System.Diagnostics.Process.Start(ProcessStartInfo 开始信息)在 Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext() 在 C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\LocalServerCodeReceiver.cs:line 89 --- 从上一个异常位置开始的堆栈跟踪结束 抛出---在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() 在 C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth\OAuth2\AuthorizationCodeInstalledApp.cs:line 77 --- 从上一个异常位置开始的堆栈跟踪结束 抛出---在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() 在 C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 134 --- 从上一个异常位置开始的堆栈跟踪结束 抛出---在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() 在 C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 60 --- 内部异常堆栈跟踪结束 --- 在 System.Threading.Tasks.Task`1.GetResultCore(布尔 waitCompletionNotification)在 WebApplication1.WebForm1.AuthenticateOauth(字符串 clientSecretJson, C:\Users\daimto\Documents\Visual Studio 中的字符串用户名) 2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:第 69 行 --- 内部异常堆栈跟踪结束 --- 在 WebApplication1.WebForm1.AuthenticateOauth(String clientSecretJson, C:\Users\daimto\Documents\Visual Studio 中的字符串用户名) 2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:第 83 行 WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\daimto\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:第 31 行 C:\inetpub\wwwroot\App_Data\MyGoogleStorage

我不是系统管理员类型的人,我对 IIS 了解甚少。我的猜测是 IIS 没有权限来生成进程?这只是一个猜测。我已经尝试将应用程序池设置为使用我自己的个人帐户,我也尝试过网络系统。

客户端库中以下问题的链接

【问题讨论】:

  • 当浏览器主机和服务器是同一台机器时,它可以正常工作,这是您在开发过程中所体验到的。互联网上的随机服务器不允许(意味着)在用户机器上启动新程序。如果你想打开一个新的浏览器窗口,你需要在客户端使用javascript。
  • 这个库已经运行多年,我们之前从未遇到过问题。
  • 也许是这样,但是您尝试使用它的方式不起作用,也不会起作用。

标签: c# asp.net iis google-oauth google-api-dotnet-client


【解决方案1】:

该库支持另一种用于 Web 应用的身份验证方式。

using System;
using System.Web.Mvc;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Mvc;
using Google.Apis.Drive.v2;
using Google.Apis.Util.Store;

namespace Google.Apis.Sample.MVC4
{
    public class AppFlowMetadata : FlowMetadata
    {
        private static readonly IAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                {
                    ClientSecrets = new ClientSecrets
                    {
                        ClientId = "PUT_CLIENT_ID_HERE",
                        ClientSecret = "PUT_CLIENT_SECRET_HERE"
                    },
                    Scopes = new[] { DriveService.Scope.Drive },
                    DataStore = new FileDataStore("Drive.Api.Auth.Store")
                });

        public override string GetUserId(Controller controller)
        {
            // In this sample we use the session to store the user identifiers.
            // That's not the best practice, because you should have a logic to identify
            // a user. You might want to use "OpenID Connect".
            // You can read more about the protocol in the following link:
            // https://developers.google.com/accounts/docs/OAuth2Login.
            var user = controller.Session["user"];
            if (user == null)
            {
                user = Guid.NewGuid();
                controller.Session["user"] = user;
            }
            return user.ToString();

        }

        public override IAuthorizationCodeFlow Flow
        {
            get { return flow; }
        }
    }
}

Web applications (ASP.NET MVC)盗取的代码

【讨论】:

  • 关于 aspnetcore 的任何帮助
  • 在 asp 上应该类似。网络核心
  • 谷歌文档中演示的演示没有使用 mvc 包,它还不能用于核心。
  • 您可以使用 GoogleAuthorizationCodeFlow(带有 asp .net 核心的新代码,代码应该与您必须尝试或等待两周直到我休假回来并可以放置一些我使用的代码相似) /跨度>
  • 感谢@DaImTo 我可以等待 2 周,但在那之前我会尝试使用 javascript api 路由来实现这一点。等待您的更新。两周后会在这里提醒。
猜你喜欢
  • 2021-05-27
  • 1970-01-01
  • 1970-01-01
  • 2011-05-07
  • 2016-03-29
  • 2016-03-02
  • 2020-03-24
  • 2016-03-04
  • 1970-01-01
相关资源
最近更新 更多