I am creating a rest API that will create user with custom attribute into our Azure AD B2C tenant using graph SDK.
Sample code below:
var oUser = new Microsoft.Graph.User()
{
AccountEnabled = true, //True by default
DisplayName = request.DisplayName,
GivenName = request.GivenName,
Surname = request.Surname,
UserPrincipalName = request.UserPrincipalName,
MailNickname = request.MailNickname,
MobilePhone = request.MobileNumber,
PostalCode = request.PostalCode,
//extesnsion_AccountId = request.AccountId,
//LeadId = request.LeadId,
PasswordProfile = new PasswordProfile() { ForceChangePasswordNextSignIn = true, Password = _configuration["AppSettings:UserDefaultPWD"] }// SET PASSWORD IN CONFIG
};
//User custom attributes
IDictionary<string, object> extensionInstance = new Dictionary<string, object>();
extensionInstance.Add("extension_{b2c-extensions-app. clientID }_{UserAttribute1}", request.attribute1);
extensionInstance.Add("extension_{b2c-extensions-app. clientID }_{UserAttribute2}", request.attribute2);
oUser.AdditionalData = extensionInstance;
var client = _graphClient.Connect();
var user = await client.Users.Request().AddAsync(oUser);
However I always get a "The following extension properties are not available" error.
The user attribute is configured in Azure portal.