che*_*xis 5 asp.net-mvc facebook facebook-graph-api asp.net-mvc-5
我们的Facebook登录目前无效.我们收到了Facebook Developer Portal的消息:
"应用程序名称"目前可以访问Graph API v2.2,该版本将于2017年3月27日达到其2年生命周期的终点.为确保平稳过渡,请将所有调用迁移到Graph API v2.3或更高版本.
要检查您的应用是否会受到此升级的影响,您可以使用版本升级工具.这将显示哪些呼叫(如果有)受此更改影响以及更新版本中的任何替换呼叫.如果您没有看到任何电话,则您的应用可能不会受到此更改的影响.
您还可以使用我们的更改日志查看所有Graph API版本中的完整更改列表.
我们正在使用ASP.NET MVC 5,我们正在使用或认证如下:
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");
Run Code Online (Sandbox Code Playgroud)
但今天,我们的登录信息对象在ExternalLoginCallback中为null:
[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...
Run Code Online (Sandbox Code Playgroud)
在Facebook开发.Portal我们的API版本是2.3
我们测试了很多选项,没有结果:
从ASP.NET MVC 5中的Facebook v2.4 API访问OAuth ExternalLoginCallback中的电子邮件地址
为什么新的fb api 2.4在带有Identity和oauth 2的MVC 5上返回null电子邮件?
非常感谢你的帮助.
小智 10
我遇到了同样的问题,这就是我如何设法解决它并从Facebook获取电子邮件.
Microsoft.Owin 到版本 3.1.0-rc1Microsoft.Owin.Security 到版本 3.1.0-rc1Microsoft.Owin.Security.Cookies 到版本 3.1.0-rc1Microsoft.Owin.Security.OAuth 到版本 3.1.0-rc1Microsoft.Owin.Security.Facebook 到版本 3.1.0-rc1然后将以下代码添加到Identity Startup类中
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);
Run Code Online (Sandbox Code Playgroud)
这是以下的定义类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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1713 次 |
| 最近记录: |