I am learning how to work with OWIN external auth using the default MVC template in VS 2015. I enabled Facebook auth and added the scope "email", expecting the user's email to be returned by Facebook after the user is authenticated (according to this). Still, there is no email in the context.User JSON object and context.Email is also null.
This is the relevant code in Startup.Auth.cs
var facebookOptions = new FacebookAuthenticationOptions
{
AppId = "XXXXXX",
AppSecret = "XXXXXX",
Provider = new FacebookAuthenticationProvider
{
OnAuthenticated = context =>
{
// Retrieve the OAuth access token to store for subsequent API calls
var accessToken = context.AccessToken;
// Retrieve the username
var facebookUserName = context.UserName;
// WHY IS IT EMPTY?
var facebookEmail = context.Email;
// You can even retrieve the full JSON-serialized user
var serializedUser = context.User;
return Task.FromResult(0);
}
}
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
Any ideas what is missing? Why is the facebook email address not being returned?