I'm trying to create users in B2C and set a mobile phone for authentication method all using delgated authority. The first step works and the user is created, but the step to create the mobile phone authentication method fails with "The user is unauthenticated". I am authenticating the user with the scopes Directory.ReadWrite.All & UserAuthenticationMethod.ReadWrite.All.
I'm using the Microsoft.Graph.Beta package. Here's the code:
// Create the user in B2C
var user = await graphServiceClient
.Users
.Request()
.AddAsync(new User {
DisplayName = request.Email,
PasswordProfile = new PasswordProfile {
ForceChangePasswordNextSignIn = true,
Password = password
},
Identities = new[] {
new ObjectIdentity {
SignInType = "emailAddress",
Issuer = "***.b2clogin.com",
IssuerAssignedId = request.Email
}
}
});
// setup the mobile phone for MFA
await graphServiceClient
.Users[user.Id]
.Authentication
.PhoneMethods
.Request()
.AddAsync(new PhoneAuthenticationMethod {
PhoneNumber = request.Mobile,
PhoneType = AuthenticationPhoneType.Mobile
});
Here's the full error details:
Microsoft.Graph.ServiceException: 'Code: unauthenticated
Message: The user is unauthenticated.
Inner error:
Message: The user is unauthenticated.
AdditionalData:
date: 2020-07-24T09:57:37
request-id: eee9ddb8-19df-49ad-a87f-8c393becb7e5
ClientRequestId: eee9ddb8-19df-49ad-a87f-8c393becb7e5
Am I doing something wrong? Or is there an issue with the API?
Any help would be greatly appreciated!