访问 azure graph api 用户列表时权限不足

Insufficent privileges when accessing azure graph api users list

我正在尝试使用图表 api 从 Azure 活动目录中获取用户。我尝试了很多方法,其中 none 有效,但让我们坚持使用最简单的方法 - 使用 this instruction and some app to make http requests (I'm using postman) I'm able to obtain autherization token with no problem. After that I want to get users list using https://graph.microsoft.com/v1.0/users,在 header 中传递令牌。我得到的不是用户列表 "Insufficient privileges to complete the operation." 这个错误消息让我很困惑,因为应用程序注册现在拥有所有可能的权限,并且拥有这个应用程序的服务帐户是全局管理员角色,所以我相信没有任何此应用程序可以获得的更多权限。

我正在开发的应用程序的任务是合并来自几家公司的用户数据,并在其中一家公司的 azure 帐户托管的网页上显示用户列表。在所有这一切中,对我来说更奇怪的是,对于其中一个域,使用图 api 访问用户数据实际上是有效的,所以逻辑上配置没有在任何地方正确设置,但我真的不知道有什么区别这使得其中一个工作正常,而其他人在 "Insufficent privileges error".

上失败

由于您将 AAD 集成到仅应用程序中,如 https://graph.microsoft.io/en-us/docs/authorization/app_only 中的描述:

After you register the application, configure the application permissions that your service or daemon app requires.

所以,首先,您可以检查您是否在Azure 门户上配置了正确的权限:

根据您的错误信息:

Insufficient privileges to complete the operation

并且应用程序权限要求您的应用程序具有管理员权限。您可以尝试将您使用的AD应用的角色升级为管理员权限。 运行 PowerShell 中的以下命令:

Connect-MsolService
$ClientIdWebApp = '{your_AD_application_client_id}'
$webApp = Get-MsolServicePrincipal –AppPrincipalId $ClientIdWebApp
#use Add-MsolRoleMember to add it to "Company Administrator" role).
Add-MsolRoleMember -RoleName "Company Administrator" -RoleMemberType ServicePrincipal -RoleMemberObjectId $webApp.ObjectId