问题描述
我们的Facebook登录现在不起作用。我们收到了Facebook开发人员门户的消息:
our Facebook Login is not working right now. We have received a message from Facebook Developer Portal:
要检查您的应用程序是否会受到此升级的影响,您可以使用
版本升级工具。这将显示哪些电话(如果有)是
受此更改影响,以及任何更新的更新的
版本。如果您没有看到任何电话,您的应用程序可能不会受到此更改
的影响。
To check if your app will be affected by this upgrade you can use the Version Upgrade Tool. This will show you which calls, if any, are affected by this change as well as any replacement calls in newer versions. If you do not see any calls, your app may not be affected by this change.
您还可以使用我们的更改日志查看完整的更改列表在
Graph API版本中。
You can also use our changelog to see the full list of changes in all Graph API versions.
我们正在使用ASP.NET MVC 5,我们正在使用或认证:
We are using ASP.NET MVC 5, and we are using or authentication like this:
var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
{
AppId = "****",
AppSecret = "****",
AuthenticationType = "Facebook",
SignInAsAuthenticationType = "ExternalCookie",
Provider = new FacebookAuthenticationProvider
{
OnAuthenticated = async ctx => ctx.Identity.AddClaim(new Claim(ClaimTypes.Email, ctx.User["email"].ToString()))
}
};
facebookAuthenticationOptions.Scope.Add("email");
但是今天,我们的登录信息对象在ExternalLoginCallback中为null:
But today, our login info object, is null in ExternalLoginCallback:
[HttpGet]
[AllowAnonymous]
[RequireHttps]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl = null)
{
try
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
... more code here...
在Facebook开发。 Portal我们的API版本是2.3
In Facebook Dev. Portal our API Version is 2.3
我们测试了许多选项,没有结果:
We have tested many options, with no results:
为什么新的fb api 2.4在MVC 5上使用Identity和oauth 2返回null电子邮件? >
Why new fb api 2.4 returns null email on MVC 5 with Identity and oauth 2?
非常感谢您的帮助。
推荐答案
同样的问题,这里是我如何设法解决它,并从Facebook获取电子邮件。
I had the same problem and here is how I managed to fix it and get the email from Facebook.
- 更新以下NuGet Pacakges
-
Microsoft.Owin
到版本3.1.0-rc1
/ li>
-
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
/ li>
- Update following NuGet Pacakges
Microsoft.Owin
to version3.1.0-rc1
Microsoft.Owin.Security
to version3.1.0-rc1
Microsoft.Owin.Security.Cookies
to version3.1.0-rc1
Microsoft.Owin.Security.OAuth
to version3.1.0-rc1
Microsoft.Owin.Security.Facebook
to version3.1.0-rc1
然后将以下代码添加到
Identity Startup
classThen add the following code to the
Identity Startup
classvar 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); } }
这篇关于版本弃用Facebook Graph API v2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
-