示例#1
0
        /// <summary>
        /// Gets the user's display photo.
        /// </summary>
        /// <param name="ssoToken">The sso access token used to make request against graph apis.</param>
        /// <param name="userId">The user to get the .</param>
        /// /// <param name="azureADSettings">Azure AD configuration settings.</param>
        /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
        public static async Task<GraphResponse<byte[]>> GetUserDisplayPhotoAsync(string ssoToken, string userId, AzureADSettings azureADSettings)
        {
            var authProvider = CreateOnBehalfOfProvider(azureADSettings, new[] { "User.ReadBasic.All" });
            GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
            GraphResponse<byte[]> response = new GraphResponse<byte[]>();

            try
            {
                var result = await graphServiceClient.Users[userId].Photos["48x48"].Content.Request().WithUserAssertion(new UserAssertion(ssoToken)).GetAsync();
                if (result == null)
                {
                    response.FailureReason = "Unable to get the user's display photo";
                    response.Result = null;

                    return response;
                }

                byte[] bytes = new byte[result.Length];
                result.Read(bytes, 0, (int)result.Length);

                response.Result = bytes;
                return response;
            }
            catch (Exception e)
            {
                response.FailureReason = e.Message;
                response.Result = null;
            }

            return response;
        }
示例#2
0
        /// <summary>
        /// Gets the Agents Calendar view.
        /// </summary>
        /// <param name="ssoToken">The sso access token used to make request against graph apis.</param>
        /// <param name="constraints">The time constraint for finding calendar view.</param>
        /// /// <param name="azureADSettings">Azure AD configuration settings.</param>
        /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
        public static async Task<GraphResponse<IEnumerable<MeetingDetails>>> GetCalendarViewAsync(string ssoToken, TimeBlock constraints, AzureADSettings azureADSettings)
        {
            var authProvider = CreateOnBehalfOfProvider(azureADSettings, new[] { "Calendars.Read" });
            GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);

            var startDateTimeParam = Uri.EscapeDataString(constraints.StartDateTime.ToString("o"));
            var endDateTimeParam = Uri.EscapeDataString(constraints.EndDateTime.ToString("o"));
            var queryOptions = new List<QueryOption>()
                      {
                           new QueryOption("startdatetime", startDateTimeParam),
                           new QueryOption("enddatetime", endDateTimeParam),
                      };

            GraphResponse<IEnumerable<MeetingDetails>> response = new GraphResponse<IEnumerable<MeetingDetails>>();

            try
            {
                var page = await graphServiceClient.Me
                    .CalendarView.Request(queryOptions)
                    .WithUserAssertion(new UserAssertion(ssoToken))
                    .GetAsync();

                List<MeetingDetails> result = new List<MeetingDetails>();
                while (page != null)
                {
                    var meetingList = page.CurrentPage;
                    foreach (var meeting in meetingList)
                    {
                        result.Add(new MeetingDetails
                        {
                            Subject = meeting.Subject,
                            MeetingTime = new TimeBlock
                            {
                                StartDateTime = meeting.Start.ToDateTimeOffset().ToUniversalTime(),
                                EndDateTime = meeting.End.ToDateTimeOffset().ToUniversalTime(),
                            },
                        });
                    }

                    if (page.NextPageRequest == null)
                    {
                        break;
                    }

                    page = await page.NextPageRequest.GetAsync();
                }

                response.Result = result.ToImmutableList();
                return response;
            }
            catch (Exception e)
            {
                response.FailureReason = e.Message;
                response.Result = new List<MeetingDetails>();
            }

            return response;
        }
示例#3
0
        /// <summary>
        /// Gets the users in a teams channel defined by channel id.
        /// </summary>
        /// <param name="teamAadObjectId">The AadObjectId id of the channel to grab users from.</param>
        /// <param name="azureADSettings">Azure AD configuration settings.</param>
        /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
        public static async Task<GraphResponse<IEnumerable<User>>> GetMembersInTeamsChannelAsync(string teamAadObjectId, AzureADSettings azureADSettings)
        {
            var authProvider = CreateClientCredentialProvider(azureADSettings);
            GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);
            GraphResponse<IEnumerable<User>> response = new GraphResponse<IEnumerable<User>>();

            try
            {
                var page = await graphServiceClient.Groups[teamAadObjectId]
                    .Members
                    .Request()
                    .GetAsync();

                List<User> result = new List<User>();

                while (page != null)
                {
                    var usersList = page.CurrentPage.ToList();
                    foreach (var user in usersList)
                    {
                        var currentUserObj = user as User;
                        result.Add(currentUserObj);
                    }

                    if (page.NextPageRequest == null)
                    {
                        break;
                    }

                    page = await page.NextPageRequest.GetAsync();
                }

                response.Result = result.ToImmutableList();

                return response;
            }
            catch (Exception e)
            {
                response.FailureReason = e.Message;
                response.Result = new List<User>();
            }

            return response;
        }