C# Google Auth在Visual studio中运行,但部署到IIS时挂起
我在和一家公司合作。它的工作方式是,当用户想要通过谷歌认证时,该库会生成一个新网页供用户进行认证C# Google Auth在Visual studio中运行,但部署到IIS时挂起,c#,asp.net,iis,google-oauth,google-api-dotnet-client,C#,Asp.net,Iis,Google Oauth,Google Api Dotnet Client,我在和一家公司合作。它的工作方式是,当用户想要通过谷歌认证时,该库会生成一个新网页供用户进行认证 System.Diagnostics.Process.Start(authorizationUrl); 我的代码使用库 credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes, userName, Cancel
System.Diagnostics.Process.Start(authorizationUrl);
我的代码使用库
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
userName,
CancellationToken.None).Result;
如果我通过VisualStudio在本地运行它,效果会很好。但是,如果我尝试部署它,它就会挂起。如果使用本地IIS使用Visual studio运行它。我得到以下错误
系统异常:CreateServiceAccountAnalyticsReporting失败--->
System.AggregateException:发生一个或多个错误。-->
System.ComponentModel.Win32异常:访问被拒绝
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
在System.Diagnostics.Process.Start(ProcessStartInfo
startInfo)在
中的Google.api.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext()
C:\apariy\v1.22\google api dotnet client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\LocalServerCodeReceiver.cs:line
89---异常发生的上一个位置的堆栈结束跟踪
投掷
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务
任务)在
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)在
Google.api.Auth.OAuth2.AuthorizationCodeInstalledApp.d_u8.MoveNext()
在里面
C:\apariy\v1.22\google api dotnet client\Src\Support\GoogleApis.Auth\OAuth2\AuthorizationCodeInstalledApp.cs:line
77---异常发生的上一个位置的堆栈结束跟踪
投掷
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务
任务)在
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)在
Google.api.Auth.OAuth2.GoogleWebAuthorizationBroker.d_uu4.MoveNext()
在里面
C:\apariy\v1.22\google api dotnet client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line
134---异常发生的上一个位置的堆栈结束跟踪
投掷
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务
任务)在
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)在
Google.api.Auth.OAuth2.GoogleWebAuthorizationBroker.d_u1.MoveNext()
在里面
C:\apariy\v1.22\google api dotnet client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line
60---内部异常堆栈跟踪的结束---at
System.Threading.Tasks.Task`1.GetResultCore(布尔值
waitCompletionNotification)位于
WebApplication1.WebForm1.AuthenticateAuth(字符串clientSecretJson,
C:\Users\daimto\Documents\Visual Studio中的字符串(用户名)
2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:第69行
---内部异常堆栈跟踪的结尾---位于WebApplication1.WebForm1.AuthenticateOauth(字符串clientSecretJson,
C:\Users\daimto\Documents\Visual Studio中的字符串(用户名)
2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:第83行
WebApplication1.WebForm1.Page_加载(对象发送方,事件参数e)
C:\Users\daimto\Documents\visualstudio
2015\Projects\WebApplication1\WebApplication1\index.aspx.cs:第31行
C:\inetpub\wwwroot\App\u Data\MyGoogleStorage
我不是一个系统管理员类型的人,我对IIS了解很少。我猜IIS没有生成进程的权限?这只是一个猜测。我尝试过将应用程序池设置为使用我自己的个人帐户,我也尝试过网络系统
指向客户端库上以下问题的链接
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; }
}
}
}
从窃取的代码当浏览器主机和服务器是同一台机器时,它可以正常工作,这是您在开发过程中遇到的情况。互联网上的随机服务器不允许在用户机器上启动新程序。如果你想打开一个新的浏览器窗口,你需要在客户端使用javascript。这个库已经存在多年了,我们以前从来没有遇到过问题。也许是这样,但你尝试使用它的方式不起作用,也不会起作用。在AspNetCore上的任何帮助应该与在asp上类似。net coreNo google文档中演示的演示使用的是mvc包,该包目前还不适用于core。您可以使用GoogleAuthorizationCodeFlow(asp.net core的新代码应该与之类似,您需要尝试或等待两周,直到我度假回来,并可以发布一些我使用的代码感谢@DaImTo,我可以等待两周,但在此之前,我将尝试javascript api路线来实现这一点。等待您的更新。两周后将在此处放置提醒。