I'm using the MS Graph API to register user on AD B2C, and it works when I tried without adding additional user attributes, but it fails with an error
properties are not available
when I tried adding those user custom attributes.
I did followed other solution thread and added clientid without '-' while setting attribute name in dictionary but doesn't work.
Here is my code snippet:
public class UserService : IUserService
{
private readonly ILogger<UserService> logger;
private readonly GraphServiceClient graphServiceClient;
private readonly string[] supportedRegionCodes;
private readonly string _clientId;
public UserService(ILogger<UserService> logger, IOptions<B2CConfiguration> options)
{
this.logger = logger;
ClientSecretCredentialOptions credentialOptions = new()
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
};
ClientSecretCredential clientSecretCredential = new(
options.Value.TenantId,
options.Value.ClientId,
options.Value.ClientSecret,
credentialOptions);
_clientId = options.Value.ClientId;
this.graphServiceClient = new GraphServiceClient(clientSecretCredential, options.Value.Scopes);
this.supportedRegionCodes = options.Value.SupportedRegionCodes;
}
public async Task<string?> RegisterUserToB2C(object userDetails)
{
try
{
string clientId = _clientId.Replace("-", string.Empty);
var user = new User
{
Identities = new List<ObjectIdentity>
{
new ObjectIdentity
{
SignInType = "userName",
Issuer ="empxxxqa.onmicrosoft.com",
IssuerAssignedId = "testuser011"
}
},
DisplayName = "Test User",
GivenName = "Test",
Surname = "User",
Mail = "[email protected]",
OtherMails = new List<string> { "[email protected]" },
PasswordProfile = new PasswordProfile
{
Password = "@w0rd123!",
ForceChangePasswordNextSignIn = true
},
UserType = "Member",
AdditionalData = new Dictionary<string, object>
{
{$"extension_{clientId}_CardId","TEST"}
}
};
var created = await graphServiceClient.Users.PostAsync(user);
return created?.Id;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
This is the error I'm getting:
The following extension properties are not available: extension_3a84xxxxxxxxxxx126f_CardId.
I've also added a screenshot of the property we created in b2c:
I'm relatively new to AD B2C and MS Graph API, do I need to add any thing at the B2C level? As without additional custom user attributes, when I tried to register, it worked, so I believe there should be no permission issues that causing it.





