phicon
phicon

Reputation: 3617

ASP Core Azure Active Directory - Get First and Last Name

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

Answers (2)

IeuanW
IeuanW

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

phicon
phicon

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

Related Questions