Google Auth在Visual Studio中运行,但在部署到IIS时会挂起 [英] Google Auth runs in Visual studio but hangs when deployed to IIS
问题描述
我正在使用 Google .Net客户端库。它的工作方式是当用户想要向Google进行身份验证时,该库会生成一个新网页供用户进行身份验证。
I am working with the Google .Net client library. The way it works is when a user wants to authenticate to Google the library spawns a new webpage for the user to authenticate with.
System.Diagnostics.Process.Start(authorizationUrl);
我使用图书馆的代码
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
userName,
CancellationToken.None).Result;
如果我通过Visual Studio在本地运行它可以正常工作。但是,如果我尝试部署它只是挂起。如果使用Visual Studio使用本地IIS运行它。我收到以下错误。
If I run this locally via Visual studio it works fine. However if I try to deploy it just hangs. If run it using Visual studio using Local IIS. I get the following error.
System.Exception:CreateServiceAccountAnalyticsReportingFailed --->
System.AggregateException:发生了一个或多个错误。 --->
System.ComponentModel.Win32Exception:在System.Diagnostics.Process.Start的
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo)中拒绝访问(ProcessStartInfo
startInfo)
Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext()in
C:\ Apiary\v1.22\google-api-dotnet-client\Src \Support\GoogleApis.Auth.DotNet4\OAuth2\LocalServerCodeReceiver.cs:line
89 ---从前一个位置开始的堆栈跟踪,其中异常是
抛出--- at
$.
的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务
任务)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)Google.Apis.Auth .OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext()
in
C:\ Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth \\ \\OAuth2\AuthorizationCod eInstalledApp.cs:line
77 ---从前一个位置开始的堆栈跟踪,其中异常是
抛出---在
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务
任务)at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)at
Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext()
in
C:\ Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line
134 ---前一个位置的堆栈跟踪结束,其中异常是
抛出---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务
任务)
系统.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)at
Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext()
in
C:\ Agpiary \v1.22\\ google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line
60 ---内部异常堆栈跟踪结束--- at
System.Threading.Tasks.Task`1.GetResultCore(Boolean
waitCompletionNotification)
WebApplication1.WebForm1.AuthenticateOauth(String clientSecretJson,
String userName)in C:\ Users \ daimto \Documents\Visual Studio
2015 \Projects \WebApplication1 \WebApplication1 \index.aspx.cs:第69行
---内部异常堆栈跟踪结束---在WebApplication1 C中的.WebForm1.AuthenticateOauth(String clientSecretJson,
String userName):\ Users \ daimto \Documents\Visual Studio
2015 \Projects\WebApplication1 \WebApplication1 \ index.xpx .cs:第83行at
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
System.Exception: CreateServiceAccountAnalyticsReportingFailed ---> System.AggregateException: One or more errors occurred. ---> System.ComponentModel.Win32Exception: Access is denied at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext() in C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\LocalServerCodeReceiver.cs:line 89 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() in C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth\OAuth2\AuthorizationCodeInstalledApp.cs:line 77 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() in C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 134 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:\Apiary\v1.22\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 60 --- End of inner exception stack trace --- at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at WebApplication1.WebForm1.AuthenticateOauth(String clientSecretJson, String userName) in C:\Users\daimto\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:line 69 --- End of inner exception stack trace --- at WebApplication1.WebForm1.AuthenticateOauth(String clientSecretJson, String userName) in C:\Users\daimto\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:line 83 at WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\daimto\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:line 31 C:\inetpub\wwwroot\App_Data\MyGoogleStorage
我不是系统管理员类型的人,我对IIS知之甚少。我的猜测是IIS没有能够产生进程的权限?这只是猜测。我已经尝试将应用程序池设置为使用我自己的个人帐户,我也尝试过网络系统。
I am not a system admin type person I have very little understanding of IIS. My guess is that IIS doesn't have the permissions to be able to spawn the process? This is just a guess. I have tried setting the application pool to use my own personal account, I have tried network system as well.
链接到客户端库上的以下问题
Links to the following issues on the Client library
- Time
- GoogleWebAuthorizationBroker.AuthorizeAsync keeps on hanging when it is hosted on IIS
- Google Calendar Api-Time out exception on IIS
推荐答案
该库支持另一种认证方式,可用于Web Apps。
The library supports another way of authenticating for use with Web Apps.
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应用程序(ASP.NET MVC)
这篇关于Google Auth在Visual Studio中运行,但在部署到IIS时会挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!