Azure active directory 无法从Active Directory检索数据

Azure active directory 无法从Active Directory检索数据,azure-active-directory,blazor-server-side,Azure Active Directory,Blazor Server Side,我使用Azure AD身份验证创建了一个新的Blazor应用程序。登录功能按预期工作。现在我需要检索特定组的用户列表。在Azure广告上,我创建了一个客户机密。此外,我还添加了Microsoft.Graph权限Directory.Read.All、Group.Read.All和 GroupMember.Read.All,并授予管理员权限许可 以下是权限: 以下是我用来检索组用户的代码: var scopes = new string[] { "https://

我使用Azure AD身份验证创建了一个新的Blazor应用程序。登录功能按预期工作。现在我需要检索特定组的用户列表。在Azure广告上,我创建了一个客户机密。此外,我还添加了Microsoft.Graph权限Directory.Read.All、Group.Read.All和 GroupMember.Read.All,并授予管理员权限许可

以下是权限:

以下是我用来检索组用户的代码:

            var scopes = new string[] { "https://graph.microsoft.com/.default" };
        var confidentialClient = ConfidentialClientApplicationBuilder
            .Create(_adSettings.ClientId)
            .WithAuthority($"{_adSettings.Instance}/{_adSettings.TenantId}/ v2.0")
            .WithClientSecret(_adSettings.ClientSecret)
            .Build();

        GraphServiceClient graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) => {
            // Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
            var authResult = await confidentialClient.AcquireTokenForClient(scopes).ExecuteAsync();

            // Add the access token in the Authorization header of the API
            requestMessage.Headers.Authorization =
            new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
        }));

            var members = await graphServiceClient.Groups["mygroup@mydomain.com"]
                .Members
                .Request()
                .GetAsync();
最后一条语句引发异常:

发送请求时出错。HttpStatusCode:404:未找到

我试着用它来代替它

var users = await graphServiceClient.Users.Request().GetAsync();

但是结果是一样的。

您应该指定组对象ID而不是组名称:

我的测试组:

测试代码和结果:

更新:

这是本测试的C#控制台应用程序代码,希望对您有所帮助:

using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
using System;



namespace graphsdktest
{
    class Program
    {
        static void Main(string[] args)
        {

            var clientId = "<Azure AD App ID>";
            var clientSecret = "<App secret>";
            var tenantID = "<tenant ID>";
            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                .Create(clientId)
                .WithTenantId(tenantID)
                .WithClientSecret(clientSecret)
                .Build();

            ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);

            var graphClient = new GraphServiceClient(authenticationProvider);

            var result = graphClient.Groups["<group ID>"].Members.Request().GetAsync().GetAwaiter().GetResult();

            foreach (var user in result) {
                Console.WriteLine(user.Id);
            }

        }
    }

}
使用Microsoft.Graph;
使用Microsoft.Graph.Auth;
使用Microsoft.Identity.Client;
使用制度;
名称空间图测试
{
班级计划
{
静态void Main(字符串[]参数)
{
var clientId=”

然后单击此按钮完成授予过程:

你好,最近怎么样?您的问题解决了吗?@Stanley Gong我有一些权限问题。我正在等待我们的IT部门解决这些问题,以便能够尝试您的建议。对于延迟,我没有忘记。非常感谢您的回答。我将尝试并让您知道。我尝试过。它没有编译时出现以下错误:“IGroupMembersCollectio”nWithReferencesPage'不包含“GetAwaiter”的定义。因此我这样使用它:var members=await graphServiceClient.Groups[“532dc7t2-991e-48wd-be62-44d920945ef5”]。members.Request().GetAsync();这给了我相同的异常。当我使用await graphServiceClient.Users.Request().GetAsync()时;,结果是一样的。@DavidShochet,谢谢你的更新。这很奇怪,我不确定它的根本原因。无论如何,我已经在我的答案中添加了我所有的代码,这是一个简单的控制台应用程序,对我来说非常适合,希望它能帮上忙:)我不知道Microsoft.Graph.Auth来自哪里。我没有看到这样的Nuget包,它也没有reco格尼兹。@DavidShochet,很高兴知道你的问题已经解决:)