I have created a tenant and registered the app with multitenant, I am able to create users, and groups and assign the groups to user by using Microsoft Graph API into the same tenant.
Appsseting.json look like--
{
"tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx",
"applicationId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx",
"applicationSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
while using "tenantId": "common" then i am getting the below error
Microsoft.Graph.ServiceException: 'Code: Authorization_IdentityNotFound
Message: The identity of the calling application could not be established.
Inner error:
AdditionalData:
date: 2023-01-04T08:00:49
request-id: 04afdea2-1009-4e8a-93b3-b6be1b7a0e41
client-request-id: 04afdea2-1009-4e8a-93b3-b6be1b7a0e41
ClientRequestId: 04afdea2-1009-4e8a-93b3-b6be1b7a0e41
I am using this below code
// The client credentials flow requires that you request the
// /.default scope, and preconfigure your permissions on the
// app registration in Azure. An administrator must grant consent
// to those permissions beforehand.
var scopes = new[] { "https://graph.microsoft.com/.default" };
// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "common";
// Values from app registration
var clientId = "YOUR_CLIENT_ID";
var clientSecret = "YOUR_CLIENT_SECRET";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var user = new User
{
AccountEnabled = true,
DisplayName = "Adele Vance",
MailNickname = "AdeleV",
UserPrincipalName = "AdeleV@Company portal .onmicrosoft.com",
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = "xWwvJ]6NMw+bWH-d"
}
};
await graphClient.Users
.Request()
.AddAsync(user);