Microsoft图形-尝试获取用户信息时权限不足

时间:2020-09-24 08:04:02

标签: c# azure-active-directory microsoft-graph-api

我正在尝试使用Microsoft图和Active Directory在用户登录系统后在angular + asp.net Web api应用程序中的隐式流程从Active Directory中获取用户信息(电子邮件,电话号码和分配的组)。

现在,我们为在Azure AD中注册的应用程序设置了一些特权,使用下面的设置,所有代码似乎都可以正常工作。

enter image description here

问题在于,这些权限似乎只用于读取个人资料信息和单个用户的组。

根据Microsoft文档委托的User.Read应该足够-link,但更改为以下设置并删除应用程序的User.Read.All

enter image description here

引发以下错误:

{
"StatusCode":500,
"Message":"Code: Authorization_RequestDenied Message: Insufficient privileges to complete the operation.
Inner error: AdditionalData: date: x request-id: x client-request-id: x ClientRequestId: x "
}

从graphClient调用用户时引发错误:

    GraphServiceClient graphClient = GetClient();

    return await graphClient.Users[userObjectId].Request()
        .GetAsync();

private GraphServiceClient GetClient()
{
    IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                .Create(ADClientId)
                .WithTenantId(TenantId)
                .WithClientSecret(ApplicationSecret)
                .Build();

    ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

    GraphServiceClient graphClient = new GraphServiceClient(authProvider);

    return graphClient;
}

现在,我不确定如何限制这些特权。流程是否有问题,C#代码还是特权不正确。

任何帮助将不胜感激。

致谢。

1 个答案:

答案 0 :(得分:1)

User.Read委派的权限允许用户登录到该应用,并允许该应用读取已登录用户的个人资料。它还允许该应用读取已登录用户的基本公司信息。

因此,您只有在获得此权限的情况下才能获得https://graph.microsoft.com/v1.0/mehttps://graph.microsoft.com/v1.0/user/{userObjectId of the signed-in user}

如果要获取其他用户的信息,请使用User.ReadBasic.AllUser.Read.All委派的权限(根据您的需要)。请注意,您需要添加委派权限,而不是应用程序权限。

enter image description here

参考here