locked
How can I get user email with External Login UseFacebookAuthentication RRS feed

  • Question

  • User-1706174896 posted

    Hi,

    I'm trying to get the external login working with UseFacebookAuthentication and hit a roadblock. Facebook authenticates the user and my Web APP gets the authenticated callback but the context Email is always null. I've requested it through the scope and the login states that the users email will be provided to the app but its not present in the response.

    I've dug pretty deep into the FacebookAuthenticationHandler source code and found that there appears to be an incorrect call to "https://graph.facebook.com/me". I don't think the email will ever be returned without "?fields=id,name,email".

    The following code snippet is how I'm setting up the external auth.

    var fbOptions = new FacebookAuthenticationOptions
    {
        AppId = "xxxxxxxxxxxxxxxx",
        AppSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        Scope = { "email", "user_friends", "public_profile" },
        SignInAsAuthenticationType = Microsoft.Owin.Security.AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app),
        Provider = new FacebookAuthenticationProvider()
        {
            OnAuthenticated = (context) =>
            {
                // Add the email id to the claim
                context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email));
                return Task.FromResult(0);
            }
        }
    };
    
    app.UseFacebookAuthentication(fbOptions);

    Has anyone ever gotten this to work?

    If so, what am I doing wrong?

    Should I just write my own Facebook handler?

    Thursday, November 26, 2015 5:50 PM

All replies

  • User-2057865890 posted


    Hi,Elip

    Welcome to asp.net forum.

    You could refer to this post,it provides an ExternalLoginCallback method.

    Best regards,
    Chris Zhao

    Friday, November 27, 2015 8:20 AM
  • User-1706174896 posted

    I will try this again but as far as I can tell the email is not being returned by Facebook unless I add 'fields=id,name,email' to the 'graph.facebook.com/me' call.

    I make the call with Postman and email is not returned when I use the Url I captured from my Web API app.

    Same Url with the addition of fields and everything works as expected.

    Friday, November 27, 2015 10:13 PM