Since 2017, this is the code that works for me (thanks to David Poxon's code above). Make sure you update version 3.1.0 from Microsoft.Owin.Security.Facebook .
In Startup.Auth.cs (or Startup.cs in some cases) put this code:
app.UseFacebookAuthentication(new FacebookAuthenticationOptions() { AppId = "***", AppSecret = "****", BackchannelHttpHandler = new HttpClientHandler(), UserInformationEndpoint = "https://graph.facebook.com/v2.8/me?fields=id,name,email,first_name,last_name", Scope = { "email" }, Provider = new FacebookAuthenticationProvider() { OnAuthenticated = async context => { context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken)); foreach (var claim in context.User) { var claimType = string.Format("urn:facebook:{0}", claim.Key); string claimValue = claim.Value.ToString(); if (!context.Identity.HasClaim(claimType, claimValue)) context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Facebook")); } } } });
Then in your external controller callback method add this code:
var firstName = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:first_name").Value;
Similarly, to get the last name, use the line above and replace urn:facebook:first_name with urn:facebook:last_name
Waqas Shah Jul 25 '17 at 6:19 2017-07-25 06:19
source share