首页 > 解决方案 > 使用 Azure 图形 API 获取用户下的用户列表

问题描述

我正在寻找实现如下方法:

如果我将经理 ID 传递给我的方法,那么它需要向我提供向该经理报告的用户列表。

我可以在哪里找到参考,如果我提供用户 ID,它会为我提供用户向其报告的经理。

获取https://graph.windows.net/myorganization/users/john@contoso.onmicrosoft.com/$links/manager?api-version=1.6

https://docs.microsoft.com/en-us/previous-versions/azure/ad/graph/api/users-operations

但我需要反过来。例如,我提供了经理 ID,我需要该经理下的用户列表。

标签: c#.netazureazure-functionsazure-ad-graph-api

解决方案


在此处安装 Microsoft Graph .NET SDK 。

使用客户端凭据提供程序生成 authProvider。

代码示例:

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithTenantId(tenantID)
    .WithClientSecret(clientSecret)
    .Build();

ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

var directReports = await graphClient.Users["{upn or user_object_id}"].DirectReports
    .Request()
    .GetAsync();

推荐阅读