Reputation: 3617
I created an Azure Active Directory Application and applied the code from the following tutorial to enable login: https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-webapp-openidconnect-aspnetcore/
After login the following returns my email adress:
Console.WriteLine(User.Identity.Name)
How would i retreive the First and Last Name of this user?
Upvotes: 3
Views: 3215
Reputation: 298
I use this, this gets you the first and last name together -
var name = claims.FirstOrDefault(c => c.Type == "name")?.Value;
Upvotes: 1
Reputation: 3617
Found it:
var fn = User.FindFirst(ClaimTypes.GivenName).Value;
var ln = User.FindFirst(ClaimTypes.Surname).Value;
System.Console.WriteLine("me :" + fn + " " + ln );
Upvotes: 8