Beispiel #1
0
        public async Task <HashSet <string> > Users()
        {
            try
            {
                var users = await _microsoftGraphApiHelper.GetUsers();

                var usersDisplayNames = new HashSet <string>();

                users
                .Where(_ => _.DisplayName != null)
                .ForEach(_ =>
                {
                    BloodHoundHelper.Users(_);
                    if (Startup.IsCosmosDbGraphEnabled)
                    {
                        CosmosDbGraphHelper.Users(_);
                    }
                    usersDisplayNames.Add(_.DisplayName);
                });

                return(usersDisplayNames);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"{nameof(Users)} {ex.Message} {ex.InnerException}");
                return(null);
            }
        }
        public static async Task <List <string> > GetUsersAsync(GraphServiceClient graphClient, HttpContext httpContext)
        {
            IUserDeltaCollectionPage userPage = new UserDeltaCollectionPage();

            userPage.InitializeNextPageRequest(
                graphClient,
                graphClient.
                Users.
                Delta().
                Request().
                Select("Id,displayName,userPrincipalName,mail").
                RequestUrl);

            var pageRequestCount = 0;
            var userIds          = new List <string>();

            do
            {
                userPage = await userPage.NextPageRequest.GetAsync(CancellationToken.None);

                userPage
                .Where(_ => _.DisplayName != null)
                .ForEach(_ =>
                {
                    if (Startup.IsCosmosDbGraphEnabled)
                    {
                        CosmosDbGraphHelper.Users(_);
                        userIds.Add(_.Id);
                    }
                });

                pageRequestCount++;
            }while (userPage.NextPageRequest != null && pageRequestCount < _maxPageRequestsPerTenant);

            return(userIds);
        }