private void OutlookSign_Click(object sender, RoutedEventArgs e) { // 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-")) { MessageBox.Show(this, "Please configure ClientId in MainWindow.xaml.cs file.", "Error"); return; } if (Rebex.Licensing.Key.Contains("_TRIAL_KEY_")) { MessageBox.Show(this, "Please set a license key in LicenseKey.cs file.", "Error"); return; } // create OAuthOutlookAuthorizationWindow that handles OAuth2 authorization statusLabel.Content = "Authenticating via Office365..."; _authenticationWindow = new OAuthAzureAuthorizationWindow(); _authenticationWindow.Owner = this; _authenticationWindow.Finished += OutlookSign_Finished; // 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 // start the authentication _authenticationWindow.Authorize(); }
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"); } }