我想当它到达GetExternalLoginInfoSync
返回 null。
我遇到了同样的问题,以下是我如何解决该问题并从 Facebook 获取电子邮件的方法。
- Update following NuGet Pacakges
-
Microsoft.Owin
到版本3.1.0-rc1
-
Microsoft.Owin.Security
到版本3.1.0-rc1
-
Microsoft.Owin.Security.Cookies
到版本3.1.0-rc1
-
Microsoft.Owin.Security.OAuth
到版本3.1.0-rc1
-
Microsoft.Owin.Security.Facebook
到版本3.1.0-rc1
然后将以下代码添加到Identity Startup
class
var facebookOptions = new FacebookAuthenticationOptions()
{
AppId = "your app id",
AppSecret = "your app secret",
BackchannelHttpHandler = new FacebookBackChannelHandler(),
UserInformationEndpoint = "https://graph.facebook.com/v2.8/me?fields=id,name,email,first_name,last_name",
Scope = { "email" }
};
app.UseFacebookAuthentication(facebookOptions);
这是定义类FacebookBackChannelHandler()
:
using System;
using System.Net.Http;
public class FacebookBackChannelHandler : HttpClientHandler
{
protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
System.Threading.CancellationToken cancellationToken)
{
// Replace the RequestUri so it's not malformed
if (!request.RequestUri.AbsolutePath.Contains("/oauth"))
{
request.RequestUri = new Uri(request.RequestUri.AbsoluteUri.Replace("?access_token", "&access_token"));
}
return await base.SendAsync(request, cancellationToken);
}
}