Facebook的MVC 5 ASP.NET身份 - 现为空对某些用户 [英] Facebook MVC 5 ASP.NET Identity - Email is null for certain users

查看:187
本文介绍了Facebook的MVC 5 ASP.NET身份 - 现为空对某些用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我试图解决现在一个月一个问题。 (尝试任何可能的文章/ code那里)。

This is a problem i am trying to solve for a month now. (tried any possible article/code out there).

在ExternalLoginCallback动作, AuthenticationManager.GetExternalLoginInfoAsync()返回一个有效的对象(与所有供应商的详细信息),但电子邮件为空对某些Facebook用户

In ExternalLoginCallback action, AuthenticationManager.GetExternalLoginInfoAsync() returns a valid object (with all the provider details) but email is null for certain Facebook users.

对于大多数Facebook登录电子邮件是presetnt。但是,对于登录的约 30%,我得到一个异常下降的过程,因为电子邮件是空。

For the large majority of Facebook login email is presetnt. But for about 30% of logins I get an exception down the process because the email is null.

幸运的是,前一段时间我已经创建了重现该问题 Facebook的用户。我在本地主机创建一个无菌的测试环境和邮件确实来自空该用户,并确定其他用户。

Luckily sometime ago I've created a Facebook user which reproduce the problem. I've created a sterile test environment in localhost and indeed email comes null for this user, and OK for other users.

*有了这个Facebook的用户,我可以登录(IMDB为例)。就好在任何大型商业网站

*With this Facebook user I can log in just fine in any big commercial site (IMDB for example).

1)我创建了一个干净的MVC 5项目,VS2013。

1) I've created a clean MVC 5 project with VS2013.

2)更新了所有有关认证的包:

2) Updated all the packages concerning authentication:

<package id="Microsoft.AspNet.Identity.Core" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Cookies" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Facebook" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security.OAuth" version="3.0.0" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />

3)无标记的Startup.Auth.cs和Facebook部分增加以下内容:

3) Unmarked the facebook section in Startup.Auth.cs and added the following:

var facebookAuthOptions = new FacebookAuthenticationOptions();
facebookAuthOptions.AppId = "***";
facebookAuthOptions.AppSecret = "***";
facebookAuthOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookAuthOptions);

更新

在该用户的Facebook的设置屏幕,我试图改变电子邮件到另一个电子邮件,然后再改回来。现在的电子邮件来就好了!怎么会这样 ?

Update

In the settings screen of that Facebook user, I tried to change the email to another email, and then change it back. Now the email comes just fine !! How could it be ?

推荐答案

这可能如果没有主电子邮件地址,该用户发生。受影响的用户必须删除的电子邮件,保存设置,然后重新添加地址,再确认,然后使它的主。为什么这个工程上的其他网站,如IMDB原因可能由事实来解释,本网站不要求电子邮件地址是从FB返回。它只是使用提供的任何信息。

This could happen if there's no primary email address for this user. The affected user must remove the email, save settings, then re-add the address, re-confirm, then make it primary. The reason why this works on other sites such as IMDB could be explained by the fact that this site doesn't require the email address to be returned from FB. It just uses whatever information is provided.

这篇关于Facebook的MVC 5 ASP.NET身份 - 现为空对某些用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆