Exemplo n.º 1
0
        private void OutlookSign_Finished(object sender, EventArgs e)
        {
            // report error if it occured
            if (_authenticationWindow.Error != null)
            {
                statusLabel.Content = "Failure.";
                MessageBox.Show(this, _authenticationWindow.Error.ToString(), "Error");
                return;
            }

            try
            {
                // obtain the credentials
                _credentials = _authenticationWindow.Credentials;

                // make sure we obtained the user name
                if (_credentials.UserName == null)
                {
                    throw new InvalidOperationException("User name not retrieved. Make sure you specified 'openid' and 'profile' scopes.");
                }

                // retrieve the list of recent messages
                GetMessageList();
            }
            catch (Exception ex)
            {
                statusLabel.Content = "Failure.";
                MessageBox.Show(this, ex.ToString(), "Error");
            }
        }
Exemplo n.º 2
0
        private async void OutlookSign_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // make sure we have an Azure application client ID and a Rebex key (feel free to remove these checks once configured)
                if (ClientId.Contains("00000000-"))
                {
                    throw new ApplicationException("Please configure ClientId in MainWindow.xaml.cs file.");
                }
                if (Rebex.Licensing.Key.Contains("_TRIAL_KEY_"))
                {
                    throw new ApplicationException("Please set a license key in LicenseKey.cs file.");
                }

                // create OAuthOutlookAuthorizationWindow that handles OAuth2 authorization
                statusLabel.Content = "Authenticating via Office365...";
                var authenticationWindow = new OAuthAzureAuthorizationWindow();
                authenticationWindow.Owner = this;

                // specify the kind of authorization we need
                // (see https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code for details)
                authenticationWindow.ClientId   = ClientId; // application's client ID
                authenticationWindow.TenantId   = TenantId; // specify kinds of users to allow
                authenticationWindow.PromptType = "";       // use default prompt type (also consider "login", "select_account", "consent", ...)
                authenticationWindow.Scopes     = Scopes;   // scope of permissions to request

                // perform the authorization and obtain the credentials
                var credentials = await authenticationWindow.AuthorizeAsync();

                // make sure we obtained the user name
                string userName = credentials.UserName;
                if (userName == null)
                {
                    throw new InvalidOperationException("User name not retrieved. Make sure you specified 'openid' and 'profile' scopes.");
                }

                // keep the credentials
                _credentials = credentials;

                // retrieve the list of recent messages
                await GetMessageListAsync();
            }
            catch (Exception ex)
            {
                statusLabel.Content = "Failure.";
                MessageBox.Show(this, ex.ToString(), "Error");
            }
        }
Exemplo n.º 3
0
        private void OutlookSign_Finished(object sender, EventArgs e)
        {
            // report error if it occured
            if (_authenticationWindow.Error != null)
            {
                statusLabel.Content = "Failure.";
                MessageBox.Show(this, _authenticationWindow.Error.ToString(), "Error");
                return;
            }

            try
            {
                // obtain the credentials
                _credentials = _authenticationWindow.Credentials;

                // retrieve the list of recent messages
                GetMessageList();
            }
            catch (Exception ex)
            {
                statusLabel.Content = "Failure.";
                MessageBox.Show(this, ex.ToString(), "Error");
            }
        }