Home > Blockchain >  How can I retrieve my Custom User Attributes (Claims) from B2C using Graph API?
How can I retrieve my Custom User Attributes (Claims) from B2C using Graph API?

Time:11-25

I have successfully created an application that uses a new B2C Tenant for authentication and I can login and call APIs.

I have added new Attributes for the Users (Roles one of them). In my "User Flows" I have 1 flow for SignIn that has selected the Roles claim one to login and one to edit users. In the following images you can see the setup and the returned claims, after editing with the User Flow.

enter image description here

And with asp.net core code, following enter image description here

===========================Update============================

You can see the claim is also a custom properity, and I got the value of this property of my specific user. The user I queried here is one which I signed up when redirect to the b2c sign up page, and the user flow is required to set this custom property.

enter image description here

I created an azure ad b2c application and set these api permission for this app.

enter image description here enter image description here

I used v1.0 version in my workaround, so I need to use $select feature to get extension property in my code, but if I used beta version here, I can get extension property directly.

enter image description here

enter image description here

CodePudding user response:

I just wanted to add a quick note to clarify that the real problem, just in case someone has the same problem, as it's a bit complicated to get started with Graph API.

The problem (as of today) is that you need to use the Beta version of the Nuget packages or the Beta (https://graph.microsoft.com/beta) graph api to retrieve all the extension attributes. The stable version doesn't work.

  1. The nuget package that worked for me is Microsoft.Graph.Beta 4.21.0-preview.
  2. The package Microsoft.Graph stable 4.11.0 published Nov 25 2021 doesn't retrieve the extension properties.
  • Related