Reputation: 53
I'm using .NET Core, with Azure B2C Authentication. 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. These Attribute are enabled in Azure AD. Thank you for your time.
Upvotes: 2
Views: 1907
Reputation: 53
Thanks to Mohit, this is the solution I found.
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.
Upvotes: 0
Reputation: 5294
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).
https://stackoverflow.com/a/43996372/6049604
Additional reference:
https://github.com/AzureADQuickStarts/B2C-GraphAPI-DotNet/blob/master/B2CGraphClient/Program.cs
Hope it helps.
Upvotes: 2