This is a problem i am trying to solve for a month now. (tried any possible article/code out there).
In ExternalLoginCallback action, AuthenticationManager.GetExternalLoginInfoAsync() returns a valid object (with all the provider details) but email is null for certain Facebook users.
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.
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.
*With this Facebook user I can log in just fine in any big commercial site (IMDB for example).
1) I've created a clean MVC 5 project with VS2013.
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) 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);
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 ?