0

I am using the default code from ASP.NET Web api for facebook authentication. The facebook cookie is being passed to my ExternalLogin endpoint. However the claims about Email is not available.

User.Identity doesnt have a value for Email or a Claim for Email.

How can I get that additional information?

app.UseOAuthBearerTokens(OAuthOptions);
app.UseCookieAuthentication(new CookieAuthenticationOptions());

        facebookAuthOptions = new FacebookAuthenticationOptions()
        {
            AppId = "xx",
            AppSecret = "xxx"
           // Provider = new FacebookAuthProvider()
        };


        facebookAuthOptions.Scope.Add("email");
        facebookAuthOptions.Scope.Add("public_profile");
       // facebookAuthOptions.SignInAsAuthenticationType = Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie;
        app.UseFacebookAuthentication(facebookAuthOptions);

FacebookAuthenticatedContext.User doesnt only contains id and name

Using the FB SDK I can see my email.. enter image description here

den
  • 709
  • 2
  • 7
  • 19

2 Answers2

0

This can happen if there is no primary email for this user in facebook. Maybe this answer can help you:

Facebook MVC 5 ASP.NET Identity - Email is null for certain users

Community
  • 1
  • 1
Alan Macgowan
  • 481
  • 1
  • 7
  • 22
  • Tried to add "context.Identity.AddClaim(new Claim("Email", context.Email));" and I get a null exception.. – den Jul 13 '15 at 22:04
  • When i use this sample API, I can see all my details .. https://supperslonic.com/SocialNetworks/OwinAuthentication – den Jul 13 '15 at 22:04
0

If the email is being provided by Facebook, it is available as part of the external login information:

var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; var loginInfo = await authenticationManager.GetExternalLoginInfoAsync();

loginInfo is of type ExternalLoginInfo from which you can retrieve the email and other claims.

DavidS
  • 2,904
  • 1
  • 15
  • 21