ASP Core Azure Active Directory - 获取名字和姓氏

phi*_*con 3 asp.net azure azure-active-directory asp.net-core

我创建了一个 Azure Active Directory 应用程序并应用了以下教程中的代码来启用登录:https : //azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-webapp-openidconnect-aspnetcore/

登录后,以下返回我的电子邮件地址:

Console.WriteLine(User.Identity.Name)
Run Code Online (Sandbox Code Playgroud)

我将如何检索该用户的名字和姓氏?

phi*_*con 7

找到了:

var fn = User.FindFirst(ClaimTypes.GivenName).Value;
var ln = User.FindFirst(ClaimTypes.Surname).Value;
System.Console.WriteLine("me :" + fn + " " + ln );
Run Code Online (Sandbox Code Playgroud)