0

As per this answer: http://stackoverflow.com/questions/20378043/getting-the-email-from-external-providers-google-and-facebook-during-account-ass/20379623#20379623

I am trying to get the email from an external provider.

This is my code:

app.UseFacebookAuthentication(
   appId: "X",
   appSecret: "Y");

app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
    ClientId = "X",
    ClientSecret = "Y"
});

The ExternalLoginCallback method in account controller is still as default:

public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

At this point loginInfo is populated correctly apart from loginInfo.Email which is always null.

No matter the account provider they all authenticate but they all have a null email.

I have create a new MVC5 project from scratch with all nuget packages up to date and the latest VS2013 code.

Three Value Logic
  • 1,102
  • 1
  • 15
  • 37

1 Answers1

0

The default MVC template code does not get an email.

The following edit to startup.configureauth fixes the problem:

var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions
{
    AppId = "X",
    AppSecret = "Y"
};

facebookOptions.Scope.Add("email");

app.UseFacebookAuthentication(facebookOptions);
Three Value Logic
  • 1,102
  • 1
  • 15
  • 37
  • is this still working for you? Since latest changes to facebook api, I cannot get the user email with this code. It is always null exactly as your original question. – zed Jul 28 '15 at 13:01