Home > Back-end >  How to get custom Azure Active Directory B2C user attributes using .NET Core
How to get custom Azure Active Directory B2C user attributes using .NET Core

Time:11-10

Using Azure B2C Active Directory. Enforcing authentication. I'm able to get the user and email address. However I do I get a custom attribute with c#?


        [Authorize]
        [HttpGet("authenticated/profile")]
        public string GetCustomAttribute()
        {
            var user = User.FindFirst(ClaimTypes.NameIdentifier);
        var customAttribute = ?
    }

Sifted through documentation and reviewed similar posts on stackoverflow.

CodePudding user response:

If you are using user flows to login to Azure AD B2C, then you may need to create the extension attribute from the portal itself.

Please refer to microsoft docs to create custom attributes. After creating, ensure you have selected the new custom attribute in the user flow settings to return it in the token. Read the claim from token to get it.

If you are using custom policies with Azure AD B2C, you could create the custom attribute using graph. Make sure you read the custom attribute and output the claim in your RP file. Microsoft docs for custom policies

CodePudding user response:

Have you verified that the attribute is included in the token? Instructions on viewing the token can be found here.

If it is not included in the token, instructions to include it can be found here

Make sure you refer to the claim by the right name, there might be an "extension_" before the name

  • Related