How to populate Azure Active Directory B2C user custom user attributes?

Viewed 1082

I've been successfully using curl to fetch and update the postal code of a user in my Azure Active Directory Tenant with commands like this:

curl -X GET https://graph.microsoft.com/v1.0/users/<userGuid>?\$select=displayName,givenName,postalCode,xyz -H "Authorization: Bearer $AAD_BEARER_TOKEN"

This displays the displayName, givenName and postalCode but ignores the custom string attribute xyz that I created using the web browser UI at portal.azure.com.

Note that since I'm using cygwin bash on windows, I have to escape my dollars and ampersands.

How can I use curl to populate this new field I created called xyz?

I've tried using open extensions but the samples don't work (possibly because they don't include a bearer token and they don't specify a specific user). Can I expect to see the custom attribute "xyz" I created with the Web UI on portal.azure.com show up?

curl -X GET https://graph.microsoft.com/v1.0/me?\$select=id,displayName,mail,mobilePhone\&\$expand=extensions

This gives me "InvalidAuthenticationToken". When I add a bearer token I get

Resource '1acbf9cc-d931-4ff3-bafe-218693fba30e' does not exist or one of its queried reference-property objects are not present.

Tue March 02 2021 evening update:

Shame on me! I forgot the most important question: how do I post/patch a new value so I have something to fetch (GET)? I cannot tell if the GET is working because the value is empty.

Wed March 03 2021 morning update: I finally found the docs on custom attributes and it says I need to modify my custom policy in TrustFrameworkExtensions.xml. Stanley: did you do this? I'm not clear on the XML for InputClaims, PersistClaims & OutputClaims. Do I need to edit this XML and upload it?

1 Answers

Per my understanding, you want to get the custom attribute value of a user by Microsoft Graph API.

If so, the attribute xyz in $select param should be:extension_<your B2C application ID remove all '-' characters>_xyz

On my side, I can find my B2C application ID here: enter image description here

And I have a custom attribute id4GTM: enter image description here

If I want to get its value of a user,the attribute name should be: extension_48c33b45c4f8419eb9d97a0f3ff1817b_id4GTM, the request URL should be :

GET https://graph.microsoft.com/v1.0/users/8bbd6746-02c7-41a6-97ca-c745c8d27a23?$select=displayname,extension_48c33b45c4f8419eb9d97a0f3ff1817b_id4GTM

Result: enter image description here

UPDATE:

If you want to set a B2C custom attribute for a user by Micorsoft Graph API, just try the request below:

request URL:

PATCH https://graph.microsoft.com/v1.0/users/<user guid>

Request Body:

{"extension_d98794e6f3ca42a6b755d6f9cca552e1_xyz": "<value you want to set>"}

On my side just as below: enter image description here

Try to get this value: enter image description here

Let me know if you have any more questions :)

Related