Hi john john Pter,
The error usually occurs if the managed identity does not have required API permissions and roles to perform the action.
- To connect to Exchange online, the managed identity must have any of the one Entra roles as mentioned in this MsDoc.
2025-05-20T19:05:01Z [Error] ERROR: [Authorization_RequestDenied] : Insufficient privileges to complete the operation.
- To resolve the above error and get users from groups, the managed identity must be assigned with
Directory.Read.All
andGroupReadWrite.All
API permission.
Hence to resolve the issue, assign API permissions like below:
Connect-MgGraph -Scopes Application.Read.All, RoleManagement.ReadWrite.Directory, AppRoleAssignment.ReadWrite.All
$params = @{
principalId = "ObjectIDofMSI"
resourceId = "2d751609-2fea-406a-8498-xxxx" ##ObjectId of Office 365 Exchange Online Enterprise application
appRoleId = "dc50a0fb-09a3-484d-be87-xxxx" #App permission ID of Exchange.ManageAsApp
}
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId "ObjectIDofMSI" -BodyParameter $params
Assign Microsoft Graph API permissions:
$params = @{
principalId = "ObjectIDofMSI"
resourceId = "c68a82f4-ecea-xxxx" #ObjectId of Microsoft Graph Enterprise application
appRoleId = "7ab1d382-f21e-4acd-a863-ba3e13f7da61" #App permission ID of Directory.Read.All
}
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId "ObjectIDofMSI" -BodyParameter $params
$params = @{
principalId = "ObjectIDofMSI"
resourceId = "c68a82f4-ecea-xxxx" #ObjectId of Microsoft Graph Enterprise application
appRoleId = "62a82d76-70ea-41e2-9197-370581804d09" #App permission ID of Group.ReadWrite.All
}
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId "ObjectIDofMSI" -BodyParameter $params
The permissions will be assigned to the managed identity successfully:
Go to Enterprise applications and search for your identity:
I assigned Exchange Admin role to the Function App's managed identity:
OUTPUT:
Connected to Microsoft Graph:
Connected to Exchange:
Hope it helps!
Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.
If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.