Search code examples
microsoft-graph-apimicrosoft-entra-id

Change Microsoft Entra External ID custom attribute using Microsoft Graph API


We are using Microsoft Entra External ID. I have defined custom user attribute TestAttribute (string) which is collected during the sign up and is also added as a claim into the JWT token. View from Entra admin center -> Enterprise applications -> Single sign-on:enter image description here

Everything works fine, the token has TestAttr value as expected (collected from sign up).

However, I want to change this value using Graph API. Previously when working with Azure B2C, this code worked fine:

var extensionInstance = new Dictionary<string, object> { { customAttribute, attributeValue } };
var updatedResult = await _graphServiceClient
    .Users[userId]
    .PatchAsync(new User
    {
        AdditionalData = extensionInstance
    });

where customAttribute was indeed extension_extAppId_testattribute. This doesn't work now - it isn't a part of JWT token anymore once I change it's value although I can see the value when using Microsoft Graph:

var user = await _graphServiceClient.Users[userId].GetAsync(config =>
{
    config.QueryParameters.Select = new[] { "extension_extAppId_testattribute" };
});

What bothers me, before changing it via API, this Get request didn't return anything, BUT the collected value was in the token. Logical assumption would be that working with the attributes is different for Entra External ID than for Azure B2C - but I have no idea how to get this to work.

So the question is, how can I change the value of a custom user attribute so that it is still part of the JWT token?

Thanks


Solution

  • I see you have defined a custom user attribute TestAttribute

    However, you update extension_extAppId_testattribute later in the source code. I think the problem you have got is case-sensitive related.

    Try to update the attribute using the following name extension_extAppId_TestAttribute.