无法从Azure Active Directory获取用户组 [英] Unable to get user groups from Azure Active Directory

查看:92
本文介绍了无法从Azure Active Directory获取用户组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用下面的代码片段从Azure Active Directory获取用户组信息.

I am trying to get user groups information from Azure Active Directory using below code snippet.

public async Task<List<string>> GetUserGroupsAsync(string alias)
{
            var groupList = new List<string>();
            try
            {
                Microsoft.Azure.ActiveDirectory.GraphClient.IUser userObject = getUserObject(alias);
                Task t = Task.Run(async () =>
                {
                    var grouppages = await ((IUserFetcher)userObject).MemberOf.OfType<Microsoft.Azure.ActiveDirectory.GraphClient.Group>().ExecuteAsync();
                    do
                    {
                        groupList.AddRange(grouppages.CurrentPage.Select(g => g.Mail != null ? g.Mail.Trim() : null).Where(eMail => !string.IsNullOrWhiteSpace(eMail)).ToList());
                        grouppages = await grouppages.GetNextPageAsync();
                    } while (grouppages != null);
                });
                t.Wait();
            }
            catch
            {
                throw;
            }
            return groupList;
}

问题:一些用户遇到了例外情况.

Issue: I am getting below exception for some users.

System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> Microsoft.Data.OData.ODataErrorException: The specified page token value has expired and can no longer be included in your request. ---> System.Data.Services.Client.DataServiceQueryException: An error occurred while processing this request. ---> System.Data.Services.Client.DataServiceClientException: {"odata.error":{"code":"Directory_ExpiredPageToken","message":{"lang":"en","value":"The specified page token value has expired and can no longer be included in your request."}}}
   at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
   at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
   at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult)
   at System.Data.Services.Client.DataServiceContext.EndExecute[TElement](IAsyncResult asyncResult)
   at Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper.<ExecuteAsync>b__6b[TSource,TInterface](IAsyncResult i)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

请帮助解决此问题.这将非常有帮助.

Please help in resolving this issue. It will be very helpful.

推荐答案

根据我的理解,当我们尝试逐页检索组的成员时会出现异常(The specified page token value has expired and can no longer be included in your request.),但是同时存在其他人正在操纵组成员,例如添加或删除.

Based on my understanding, the exception(The specified page token value has expired and can no longer be included in your request.) will occur when we are trying to retrieve the group's members page by page however at the same time there are others are manipulating the groups members like adding or deleting.

我们需要在代码中处理此异常.例如,在收到此异常后,我们可以通知用户和信息用户重试获取成员.

We need to handle this exception in the code. For example, we can notify the users and info users to retry to get the members after we get this exception.

这篇关于无法从Azure Active Directory获取用户组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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