[英].NET Core using Azure B2C Authentication, looking for the User Attributes such as @User.Identity.UserID after logged in
I'm using .NET Core, with Azure B2C Authentication.我正在使用 .NET Core 和 Azure B2C 身份验证。 On the project I'm developing, I can find the @User.Identity.Name, but I cant find the C# object name/path for the other "built in" User Attributes such as @User.Identity.UserID , @User.Identity.firstTimeLogging, @User.Identity.firstName.
在我正在开发的项目中,我可以找到@User.Identity.Name,但我找不到其他“内置”用户属性(例如 @User.Identity.UserID 、@User)的 C# 对象名称/路径。 Identity.firstTimeLogging,@User.Identity.firstName。 These Attribute are enabled in Azure AD.
这些属性在 Azure AD 中启用。 Thank you for your time.
感谢您的时间。
You can access custom claims by including them in the token sent to the app or by querying the Azure AD Graph API (not the Microsoft Graph yet).您可以通过将自定义声明包含在发送到应用程序的令牌中或通过查询 Azure AD Graph API(还不是 Microsoft Graph)来访问自定义声明。
https://stackoverflow.com/a/43996372/6049604 https://stackoverflow.com/a/43996372/6049604
https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-devquickstarts-graph-dotnet?tabs=applications https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-devquickstarts-graph-dotnet?tabs=applications
Additional reference:补充参考:
https://github.com/AzureADQuickStarts/B2C-GraphAPI-DotNet/blob/master/B2CGraphClient/Program.cs https://github.com/AzureADQuickStarts/B2C-GraphAPI-DotNet/blob/master/B2CGraphClient/Program.cs
Hope it helps.希望能帮助到你。
Thanks to Mohit, this is the solution I found.感谢 Mohit,这是我找到的解决方案。
var claimsIdentity = (System.Security.Claims.ClaimsIdentity)User.Identity;
List<String> termsList = new List<String>();
foreach (var claim in claimsIdentity.Claims)
{
termsList.Add(claim.Value);
}
//The 2nd item in the claim is the objectidentifier
Debug.WriteLine(termsList[2]);
// there is probably a cleaner way, but it works for me.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.