rad*_*scu 2 facebook oauth-2.0 asp.net-web-api
我使用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
}
Run Code Online (Sandbox Code Playgroud)
任何配置都不会在本地开发服务器上抛出异常.但它在具有以下错误的实时服务器上失败.
知道为什么吗?
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
Run Code Online (Sandbox Code Playgroud)
其他信息:看起来我无法连接到网址,因为我收到此错误: Unable to connect to the remote server
小智 7
自从过去5天以来我遇到了同样的问题,2天前看到了你的问题,但那段时间我没有得到答案.
解决方案:您可能正在使用Smarterasp.net作为您的托管服务提供商.他们在"安全选项卡"中引入了一个附加设置,默认情况下他们拒绝任何内部连接到graph.facebook.com.但是如果你需要这个,你必须"启用"这个设置.
祝好运
归档时间: |
|
查看次数: |
409 次 |
最近记录: |