public FolderViewerForm(PublicClientApplication PCA, Microsoft.Identity.Client.IUser CurrentUser, FolderInfo TargetFolderInfo, string TargetFolderDisplayName)
        {
            InitializeComponent();

            pca                     = PCA;
            currentUser             = CurrentUser;
            targetFolder            = TargetFolderInfo;
            targetFolderDisplayName = TargetFolderDisplayName;
        }
Exemple #2
0
        public AttachmentViewerForm(PublicClientApplication PCA, Microsoft.Identity.Client.IUser CurrentUser, FolderInfo TargetFolderInfo, string TargetItemID, string TargetItemSubject)
        {
            InitializeComponent();

            pca               = PCA;
            currentUser       = CurrentUser;
            targetFolder      = TargetFolderInfo;
            targetItemId      = TargetItemID;
            targetItemSubject = TargetItemSubject;
        }
Exemple #3
0
        private bool Prepare()
        {
            // Use MSAL and acquire access token.

            AcquireViewerTokenForm acuireViewerTokenForm = new AcquireViewerTokenForm();

            if (acuireViewerTokenForm.ShowDialog(out pca, out ar) != DialogResult.OK)
            {
                return(false);
            }

            string token = ar.AccessToken;

            currentUser = ar.User;

            try
            {
                client = new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"),
                                                   () =>
                {
                    return(Task.Run(() =>
                    {
                        return token;
                    }));
                });

                client.Context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(
                    (eventSender, eventArgs) => InsertXAnchorMailboxHeader(eventSender, eventArgs, currentUser.DisplayableId));

                // Get the root folder.
                GetRootFolder();

                // Get CalendarFolders (Calendars)
                GetCalendarFolders();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ERROR retrieving folders: {0}", ex.Message, "Office365APIEditor"));

                return(false);
            }
        }
        private bool Prepare()
        {
            // Use MSAL and acquire access token.

            AcquireViewerTokenForm acuireViewerTokenForm = new AcquireViewerTokenForm();

            if (acuireViewerTokenForm.ShowDialog(out pca, out ar) != DialogResult.OK)
            {
                return(false);
            }

            string token = ar.AccessToken;

            currentUser = ar.User;

            try
            {
                viewerHelper = new ViewerHelper.ViewerHelper(pca, currentUser);

                // Get the Drafts folder.
                GetDraftsFolderAsync();

                // Get the root folder.
                PrepareMsgFolderRootAsync();

                // Create Calendar dummy root folder.
                PrepareCalendarRootFolder();

                // Create TaskGroup dummy root folder.
                PrepareTaskGroupRootFolder();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ERROR retrieving folders: {0}", ex.Message, "Office365APIEditor"));

                return(false);
            }
        }
        public static OutlookServicesClient GetOutlookServicesClient(PublicClientApplication pca, Microsoft.Identity.Client.IUser CurrentUser)
        {
            // Acquire access token again.

            OutlookServicesClient newClient = new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"),
                                                                        () =>
            {
                return(Task.Run(async() =>
                {
                    string accessToken = await GetAccessTokenAsync(pca, CurrentUser);
                    return accessToken;
                }));
            });

            newClient.Context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(
                (eventSender, eventArgs) => InsertHeaders(eventSender, eventArgs, CurrentUser.DisplayableId));

            return(newClient);
        }
        public static async Task <string> GetAccessTokenAsync(PublicClientApplication pca, Microsoft.Identity.Client.IUser CurrentUser)
        {
            // Acquire access token.
            // This method is designed for GetOutlookServiceClient(), so if you need new OutlookServiceClient and new Access Token, you should use GetOutlookServiceClient().

            AuthenticationResult ar;

            try
            {
                ar = await pca.AcquireTokenSilentAsync(MailboxViewerScopes(), pca.Users.Where(u => u.DisplayableId == CurrentUser.DisplayableId ).First());
            }
            catch (Exception)
            {
                try
                {
                    ar = await pca.AcquireTokenAsync(MailboxViewerScopes(), CurrentUser, UIBehavior.ForceLogin, "");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(ar.AccessToken);
        }
Exemple #7
0
        public static async Task <string> GetAccessToken(PublicClientApplication pca, Microsoft.Identity.Client.IUser CurrentUser)
        {
            // Acquire access token.
            // This method is designed for GetOutlookServiceClient(), so if you need new OutlookServiceClient and new Access Token, you should use GetOutlookServiceClient().

            Microsoft.Identity.Client.AuthenticationResult ar;

            try
            {
                ar = await pca.AcquireTokenSilentAsync(Office365APIEditorHelper.MailboxViewerScopes(), CurrentUser);
            }
            catch (Exception extemp)
            {
                try
                {
                    ar = await pca.AcquireTokenAsync(Office365APIEditorHelper.MailboxViewerScopes(), CurrentUser, UIBehavior.ForceLogin, "");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(ar.AccessToken);
        }