users.get(principalID) 的 azure-graph 权限

azure-graph permission for users.get(principalID)

我的代码(Node.js):

const GraphkManagementClient = require('azure-graph');
client = new GraphkManagementClient(credentials, tenantId);
client.users.get(principalID);

最后一行抛出:

Authorization_RequestDenied: Insufficient privileges to complete the operation.

我知道如何在 Azure 门户上授予权限,但我不知道执行此操作的 azure-graph 的正确权限是哪个。名单好长:

(这只是列表的开头)

根据您在 Azure Active Directory 中应用注册的 Microsoft Graph 权限,授予 'Read Directory Data' 权限。这应该足以使调用工作。如果太高,请参考此以获取更多信息:

Microsoft Graph Permissions Reference

首先,根据问题中的屏幕截图,您为错误的 API 分配了权限。它显示 "Microsoft Graph" 尽管您的代码将使用 Azure AD Graph API.

在 Azure 门户中导航到 Azure Active Directory > 应用注册 > 你的应用 > 所需权限 > 添加(现在在 Select 和 API select "Windows Azure Active Directory" 中)

现在,如果您的代码中使用的凭据是客户端 id/app id 和应用密码,那么您需要在应用程序权限下分配 "Read directory data"。对于 msRestAzure.loginWithServicePrincipalSecret

这样的代码

否则,如果您提示用户输入他们的凭据并执行交互式登录之类的操作,请在委派权限下分配 "Read directory data"。对于 msRestAzure.interactiveLogin()

这样的代码

分配相关权限后,如果其中任何一项需要管理员同意,就像我在上述两种情况下显示的那样,请征得管理员同意。您可以在流程结束时使用 "Grant Permissions" 按钮方便地为同一租户执行此操作。