GoogleWebAuthorizationBroker.AuthorizeAsync 在暂存服务器中失败


GoogleWebAuthorizationBroker.AuthorizeAsync()

(农场,4.5 NET)暂存服务器上失败,但在本地服务器中效果很好。我已经遵循了帮助热线上的所有代码,但仍然无济于事。

这是我的代码:

String gpath = Server.MapPath("credentials/siteAPI.json");
UserCredential credential;
string credPath = Server.MapPath("credentials");
using (var stream = new FileStream(gpath, FileMode.Open, FileAccess.Read))
{
      credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { CalendarService.Scope.Calendar },//
                    "xx@ccc.com",
                    CancellationToken.None,
                     new AppDataFileStore(credPath)
                    ).Result;
}

我收到此错误:

System.AggregateException: One or more errors occurred.
---> System.ComponentModel.Win32Exception: Access is denied
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
    at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:UsersmdrilDocumentsGitHubgoogle-api-dotnet-clientSrcGoogleApis.Auth.DotNet4OAuth2GoogleWebAuthorizationBroker.cs:line 59
--- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
    at System.Threading.Tasks.Task`1.get_Result()
    at z2.Page_Load(Object sender, EventArgs e) in e:hostingspacescal1234mysitecalendar.comwwwrootz2.aspx.cs:line 169
---> (Inner Exception #0) System.ComponentModel.Win32Exception (0x80004005): Access is denied
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
    at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:UsersmdrilDocumentsGitHubgoogle-api-dotnet-clientSrcGoogleApis.Auth.DotNet4OAuth2GoogleWebAuthorizationBroker.cs:line 59<---

根据我阅读的其他注释,这是由于服务器端的权限问题,但是对于农场站点,我无法再控制任何权限。

有趣的是,当我将其中一个批准的凭据从本地服务器复制到暂存服务器时,一切正常!登台服务器似乎无法(或没有权限)启动屏幕以请求用户令牌批准!

我该如何解决这个问题?

我花了几个小时在同一个问题上,终于找到了一个帮助我解决问题的帖子。帖子在这里 http://answers.flyppdevportal.com/MVC/Post/Thread/7819b19d-07d0-4584-a061-cace0688bfb2?category=sharepointdevelopment

在此代码为我工作的开发服务器上,在 credPath(请参阅上面的代码中的此变量)文件夹中创建了一个令牌响应文件。

只是将此文件复制到暂存服务器,它对我不起作用。这为我解决了问题。

这可能是因为向用户显示同意网页的页面(在开发服务器中工作),并且在这种情况下无法显示导致此错误的页面。同样,这都是理论,但上述解决方案对我有用。

最新更新