Microsoft Graph API:在总共13位用户中仅返回一位用户 [英] Microsoft Graph API: returning only one user out of total 13 users

查看:46
本文介绍了Microsoft Graph API:在总共13位用户中仅返回一位用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 UWP 应用程序中,我正在使用

更新:

要回答用户 @Allen Wu 的查询:

a)我已经安装了以下 NuGet 软件包:

 安装包Microsoft.Toolkit.Uwp.Ui.Controls-版本6.0.0安装包Microsoft.Toolkit.Uwp.Ui.Controls.DataGrid-版本6.0.0安装包Microsoft.Toolkit.Graph.Controls -IncludePrerelease 

我正在将变量 graphClient 设置为 ProviderManager.Instance.GlobalProvider.Graph;

b)我已经使用倒数第二个帐户(如图1所示的Microsoft hotmail 帐户)和倒数第二个帐户(Microsoft Outlook 帐户)测试了该应用程序我都分配了一个全局管理员角色.但是它们不是Azure AD帐户.

解决方案

您应该提供您的代码,以便我可以修改或指出不正确的部分.

但是无论如何我都找到了原因.

Microsoft hotmail 帐户和Microsoft Outlook 帐户这两个帐户实际上是MSA(Microsoft个人帐户).

尽管已将它们作为来宾用户添加到您的租户中,但是,如果您的身份验证终结点为 common ,则此帐户将被视为个人帐户,而不是该租户下的来宾用户.请参见此处.在您的代码中,默认情况下使用的是 common ,因此该用户被视为MSA,并且只能获取自己的信息.

因此,您需要在请求中指定租户ID .我不确定您如何生成 graphClient .但是您可以参考官方文档列出用户示例.

但仍要记住修改 WithAuthority .

此处为示例:

  IConfidentialClientApplication ConfidentialClientApplication = ConfidentialClientApplicationBuilder.Create(客户编号).WithRedirectUri(redirectUri).WithAuthority("https://login.microsoftonline.com/{tenant id}/v2.0").WithClientSecret(clientSecret)//或.WithCertificate(certificate).建造();AuthorizationCodeProvider authProvider =新的AuthorizationCodeProvider(confidentialClientApplication,作用域);GraphServiceClient graphClient = new GraphServiceClient(authProvider);var users =等待graphClient.Users.要求().GetAsync(); 

In my UWP app, I am using Microsoft Graph SDK. My Azure account has total 13 users that I want to display in my UWP app using the following query. But the query is returning only one (the logged in user). It happens even when I logged in as Global admin. Moreover, the userType of the user is shown as Null

var users = await graphClient.Users.Request()
    .Select("displayName, userPrincipalName, userType")
    .GetAsync();

Authorization Scopes in my App: User.Read User.Read.All

Azure Portal showing the list of all users:

NOTE: The above query in the UWP returns only one of these users (the logged in user)

API Permissions of the Registered App in Azure:

UPDATE:

To answer an inquiry from user @Allen Wu:

a) I've installed the following NuGet packages:

Install-Package Microsoft.Toolkit.Uwp.Ui.Controls -Version 6.0.0
Install-Package Microsoft.Toolkit.Uwp.Ui.Controls.DataGrid -Version 6.0.0
Install-Package Microsoft.Toolkit.Graph.Controls -IncludePrerelease

And I'm using setting the variable graphClient as ProviderManager.Instance.GlobalProvider.Graph;

b) I have tested the app using the third to last account (Microsoft hotmail Account shown in image 1) and the second to last account (Microsoft Outlook account) both of which I have assigned a Global Administrator role. But they are not the Azure AD accounts.

解决方案

You should provide your code so that I can modify or point out the incorrect part.

But anyway I have found the reason.

The two accounts Microsoft hotmail Account and Microsoft Outlook account are actually MSA (Microsoft personal account).

Although they have been added as guest users into your tenant, if your authentication endpoint is common, then this account will be treated as a personal account instead of a guest user under this tenant. See reference here. In your code you are using common by default, so the user is treated as MSA and it can only get its own information.

So you need to specify the tenant id in the request. I'm not sure how you generate the graphClient. But you can refer to the official document Authorization code provider and List users example.

But still remember to modify WithAuthority.

An example here:

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithRedirectUri(redirectUri)
    .WithAuthority("https://login.microsoftonline.com/{tenant id}/v2.0")
    .WithClientSecret(clientSecret) // or .WithCertificate(certificate)
    .Build();

AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(confidentialClientApplication, scopes);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

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

这篇关于Microsoft Graph API:在总共13位用户中仅返回一位用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆