【问题标题】:Any idea why Facebook Provider fails in the below code?知道为什么 Facebook Provider 在下面的代码中失败了吗?
【发布时间】:2016-07-24 18:24:00
【问题描述】:

我使用 Facebook 为我的 WebAPI 服务实现了 OAUTH 登录,我通过以下方法获取令牌:

private static async Task<ExternalLoginData> FromToken(string provider, string accessToken)
        {
            if (string.IsNullOrEmpty(provider))
                return null;

            provider = provider.Trim().ToLower();

            string verifyTokenEndPoint = "", verifyAppEndpoint = "";
            HttpClient client = new HttpClient();

            if (provider == ProviderConstants.Facebook)
            {
                verifyTokenEndPoint = $"https://graph.facebook.com/me?access_token={accessToken}";
                verifyAppEndpoint = $"https://graph.facebook.com/app?access_token={accessToken}";
            }
            else
            {
                return null;
            }

            Uri uri = new Uri(verifyTokenEndPoint); 
            HttpResponseMessage response = await client.GetAsync(uri); <-- exception thrown here

            if (response.IsSuccessStatusCode)
            {
                //not relevant
            }

            //not relevant
        }

在任何配置的本地开发服务器上都不会引发异常。但它在实时服务器上失败并出现以下错误。

知道为什么吗?

Failed when generating token
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 1.1.1.1:443
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at FishingApp.Controllers.AccountController.<FromToken>d__32.MoveNext() in E:\TeamCity\buildAgent\work\22810208a40a1b66\src\FishingApp\Controllers\AccountController.cs:line 1033
--- 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 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at FishingApp.Controllers.AccountController.<LoginExternalToken>d__30.MoveNext() in E:\TeamCity\buildAgent\work\22810208a40a1b66\src\FishingApp\Controllers\AccountController.cs:line 865

附加信息:看起来我无法连接到 url,因为我收到此错误:Unable to connect to the remote server

【问题讨论】:

    标签: facebook asp.net-web-api oauth-2.0


    【解决方案1】:

    自过去 5 天以来我一直遇到同样的问题,2 天前看过你的问题,但那次我没有答案。

    解决方案: 可能您正在使用 Smarterasp.net 作为您的托管服务提供商。 他们在“安全选项卡”中引入了一个附加设置,默认情况下他们拒绝任何内部连接到 graph.facebook.com。但是如果你需要这个,你必须“启用”这个设置。

    Smarterasp Snapshot

    祝你好运

    【讨论】:

    • 沙巴兹!你是男人!我花了 2 天时间没有质疑我的托管。确实是 smarterasp,net。让我试试修复。
    猜你喜欢
    • 1970-01-01
    • 2019-09-17
    • 2013-03-25
    • 2011-02-14
    • 2017-04-24
    • 2014-04-08
    • 2020-01-04
    • 2021-12-30
    • 1970-01-01
    相关资源
    最近更新 更多