When adding a user to our B2C AD with external email address domains we are getting this error: The domain portion of the userPrincipalName property is invalid. You must use one of the verified domain names in your organization.
We want to create new users who have different domain email addresses. We do not want to "Invite" a user, we want to create them in our system.
This is the code that we are using:
var clientSecretCredential = new ClientSecretCredential(config.TenantId, config.AppId, config.ClientSecret);
GraphServiceClient graphClient = new GraphServiceClient(clientSecretCredential);
var requestBody = new User()
{
AccountEnabled = true,
DisplayName = $"{profileModel.FirstName} {profileModel.LastName}",
MailNickname = profileModel.NickName,
UserPrincipalName = profileModel.EmailAddress,
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = "xxxxxxxxxx",
},
};
var b2cResult = await graphClient.Users.PostAsync(requestBody);`