I'm building an application using ASP.NET MVC and Identity and I have Google logins working, but I'd like to display the user's name (from Google/Facebook), so that rather than the website showing as "Hi [email protected]" it displays as "Hi Fred". I'm aware of how to customise the ApplicationUser, it's just the interaction with the providers I'm not too sure about.
Can anyone help?
On ExternalLoginCallback
method you can get all the details.
//code omitted for clarity
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
var identity = AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
var emailClaim = identity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
var lastNameClaim = identity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Surname);
var givenNameClaim = identity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.GivenName);
var email = emailClaim.Value;
var firstName = givenNameClaim.Value;
var lastname = lastNameClaim.Value;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With