Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception Azure AD B2C Setting Custom Attribute With GraphServiceClient

Following directions from here: https://learn.microsoft.com/en-us/azure/active-directory-b2c/user-flow-custom-attributes?pivots=b2c-user-flow

enter image description here

I am able to create and get users fine:

// This works!
var graphServiceClient = new GraphServiceClient(
                    $"https://graph.microsoft.com/beta",
                    AuthenticationProvider);
var user = await graphClient.Users[userId].Request().GetAsync();

if (user.AdditionalData == null)
    user.AdditionalData = new Dictionary<string, object>();
user.AdditionalData[$"extension_xxxxxxx_Apps] = "TestValue";
// this does not work!
result = await graphClient.Users[user.Id].Request().UpdateAsync(msGraphUser);

For xxxxxxx I tried both the Client ID and Object Id from the b2c-extensions-app in my tenant.

Exception

Microsoft.Graph.ServiceException: 'Code: Request_BadRequest Message: The following extension properties are not available: extension_xxxxxxx_Apps.

How can I set a custom attribute from GraphServiceClient?

like image 678
dan Avatar asked Feb 19 '26 15:02

dan


1 Answers

Try creating a "new" user rather getting the existing one. When you call UpdateAsync, B2C will only set the properties that you provide (it won't overwrite the other props with null). This may or may not help, but the thing is, we're doing the same thing you do above except with a "new" User, and it works for us.

User b2cUser = await this.GetOurUser(userId);
var additionalData = new Dictionary<string, object>();
additionalData["extension_id-of-extensions-app-here_Foo"] = "Ice Cream Cone";
var updatedB2cUser = new User
{
    AdditionalData = additionalData
};

await this.GraphServiceClient.Users[b2cUser.Id].Request().UpdateAsync(updatedB2cUser);

In practice, we include additional props such as Identities, because we use B2C as an identity provider...so the above is some pared-down code from our B2C wrapper showing just the "custom property" part.

Update Actually, you may just need to remove the hyphens from your extension-app ID and double-check which one you're using.

enter image description here

like image 114
System.Cats.Lol Avatar answered Feb 27 '26 09:02

System.Cats.Lol