I've decided on using the Microsoft.Graph
.NET SDK instead of using the old Azure Graph API with manual HTTP requests.
The problem is that when I try to create a new user with some email, e.g. [email protected]
var req = _client.Users.Request();
var userRes = req.AddAsync(new User()
{
AccountEnabled = true,
DisplayName = user.Email,
MailNickname = user.GivenName,
GivenName = user.GivenName,
Surname = user.SurName,
UserPrincipalName = user.Email,
PasswordProfile = new PasswordProfile()
{
Password = user.Password,
ForceChangePasswordNextSignIn = true
},
PasswordPolicies = "DisablePasswordExpiration, DisableStrongPassword",
Country = user.Country,
City = user.City,
PostalCode = user.ZipCode
}).Result;
I get an exception that says 'Property userPrincipalName is invalid'
I'm only able to create the user when I use an email with the tenant as a domain, e.g. [email protected]
But this is not what I need.
I need to be able to create actual external users programaticaly.
With Azure Graph API it works Is there a way to make it work with the Microsoft Graph API?