GoogleWebAuthorizationBroker无法从IIS主机运行

我使用以下代码使用Google .Net客户端库向Google进行身份validation。

public static void auth() { string clientId = "xxxxxx.apps.googleusercontent.com"; string clientSecret = "xxxxx"; string[] scopes = new string[] { "https://www.googleapis.com/auth/contacts.readonly" }; // view your basic profile info. try { // Use the current Google .net client library to get the Oauth2 stuff. UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret } , scopes , "test" , CancellationToken.None , new FileDataStore("test")).Result; // Translate the Oauth permissions to something the old client libray can read OAuth2Parameters parameters = new OAuth2Parameters(); parameters.AccessToken = credential.Token.AccessToken; parameters.RefreshToken = credential.Token.RefreshToken; RunContactsSample(parameters); } catch (Exception ex) { Console.WriteLine(ex.Message); } } 

我正在使用自己的客户端ID和客户端密钥。 当我从visual studio运行时,此代码完全正常工作,但在IIS中托管后无效。

我在google api控制台中提到重定向的URI是http:// localhost / authorize /

我的IIS主机Url是http://localhost/googleintegration.aspx

我在最后一个月面对这个问题,有谁可以为此提供解决方案..

(重新发布自https://github.com/google/google-api-dotnet-client/issues/888 )

GoogleWebAuthorizationBroker用于在最终用户计算机上本地运行的应用程序。 它在本地打开Web浏览器允许用户进行身份validation。 听起来你正试图在IIS中从服务器机器上使用GoogleWebAuthorizationBroker ; 它将无法工作,因为它将尝试在该服务器计算机上打开Web浏览器 – 这将失败,并且最终用户无法看到,因为它将在服务器计算机上,而不是他们的计算机上。

我自己没有这样做,但看起来这里的指令 (对于ASP.NET MVC Web应用程序)可能有所帮助。