使用 Microsoft Graph 客户端库访问 user.MemberOf [英] Access user.MemberOf with Microsoft Graph Client Library

查看:63
本文介绍了使用 Microsoft Graph 客户端库访问 user.MemberOf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我最初提出这个问题客户端库存储库,他们回应说这是服务库中的问题,而不是 .NET 库中的问题.

Note: I originally posed this question in the client library repo and they responded that this is an issue in the service library, not the the .NET library.

在开发过程中,我们一直在做这样的事情来获取用户组:

During development we have been doing something like this to get a user's groups:

var user = await GraphClient.Users[userId].Request().Expand("memberOf").GetAsync();

其结果被提供给一个方法,该方法将使用可能返回的NextPageRequest"对象来获取当前页面之外的结果.我们的虚假开发用户帐户以及早期的真实用户从来没有足够的组成员资格来要求 NextPageRequest 逻辑,并且忘记了对其进行测试.

The result of which was fed to a method that would use the presumably returned "NextPageRequest" object to get results beyond the current page. Our fake development user accounts, as well as early real users never had enough group memberships to require the NextPageRequest logic, and testing of it was forgotten about.

在获得 20 多个组的用户后,最终清楚地表明,按照上述方式发出请求会返回一页的成员资格,但不会返回 NextPageRequest 以用于后续请求的选项.你关于集合的文档使它看起来应该是这样的.

After getting users with 20+ groups it eventually became clear that making a request as detailed above returns one page worth of memberships but does not return a NextPageRequest to use in the options of subsequent requests. Your documentation around collections makes it seem like this is how it should be done.

我相信你已经知道,一种有效的方法是这样的:

As I'm sure you already know, a way that does work is like this:

ListuserGroups = await GraphClient.Users[userId].MemberOf.Request().GetAsync().CurrentPage.Where(p => p.GetType() == typeof(Microsoft.Graph.Group)).Cast().ToList();

就我们所见,这将返回用户的所有组成员身份.如果意图是扩展不与memberOf"一起使用,那么它根本不应该工作.现在,对于租户中的 800 个用户中的大约 760 个,旧代码运行良好,其余的是编写支票的用户:).如果我们做的 .Expand("memberOf") 不正确,请告诉我.

This, as far as we have seen, returns all of the user's group memberships. If the intent is that Expand not be used with "memberOf", then it shouldn't work at all. Right now the old code worked fine for around 760 of the 800 users in the tenant, the remainder being the ones that write the checks :). If we were doing .Expand("memberOf") incorrectly, let me know please.

此外,GetMemberGroups 的工作方式与 MemberOf 不同.意图是什么?也许做一些像 GetMemberGroups(securityEnabledOnly = false, expandGroupInfo = false) 可能会更清楚.

Also, GetMemberGroups works differently than MemberOf. What's the intent? Maybe doing something like GetMemberGroups(securityEnabledOnly = false, expandGroupInfo = false) might be clearer.

推荐答案

您的观察是正确的.$expand 在 Directory 中有些限制,最多只能扩展 20 项,不支持分页.对于其他 Graph 服务,这不一定是正确的.请参阅 https://graph.microsoft.io/en-us/docs/overview/query_parameters 和 $expand,这里有记录.

Your observations are correct. $expand is somewhat limited in Directory, and will only expand up to 20 items and does not support pagination. This is not necessarily true for other Graph services. See https://graph.microsoft.io/en-us/docs/overview/query_parameters and $expand, where this is documented.

不幸的是,改变行为以返回诸如 $expand=memberOf 之类的不受支持的错误将代表破坏性更改.我们可以考虑在新版本中进行此更改.

Unfortunately changing behavior to return an unsupported error for things like $expand=memberOf would represent a breaking change. We could consider this change for a new version.

我们还希望向 Graph 元数据文档添加更多注释,这些注释可能能够描述支持展开和分页的位置.这也有助于限制客户端库不显示服务不支持的选项.

We are also looking to add more annotations to the Graph metadata document that might be able to describe where expand and pagination is supported. This will also help limit the client library not to show options that the service cannot support.

希望这会有所帮助,

这篇关于使用 Microsoft Graph 客户端库访问 user.MemberOf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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