Skip to main content

Configuring Email Clients for Outlook 365 Accounts using Oauth2.0

UseOauth2 support has been added for email clients such as Outlook that have deprecated basic authentication for IMAP email and moved to Oauth.

Support for this articlewas whenadded AIQ-relatedin emailthe testingAIQ or4.8.8 serviceand flows require OAuth 2.4.9.0 accessreleases.

Setting up Azure

    Go to Outlook>Azure (https://portal.azure.com/) and sign in with your credentials.

    Expand the left side menu and select Azure Active Directory.

    In the left side menu, select App registrations.

    Click New Registration.

    Enter a name to identify your application.

    In Supported account types, select Accounts in this organizational directory only (Single tenant).

    Click Register.

    In the left side menu, click API Permissions.

    Delete any existing permissions.

    Click Add a permission.

    Select the APIs my organization uses tab.

    Search for “Office 365 mailboxes.Exchange Online“. In the select permissions search box type “IMAP“ and select the results.

    Click Update permissions.

    This permission needs to be authorized by an administrator of your organization. If your are the administrator, click Grant admin consent for {Organization}. If you’re not an administrator, please contact an administrator to authorize this permission.

    Save the values in the Overview page. You will need them in the command line configuration steps.

    ValidationCommand workflowLine Configurations

      Confirm

      Run Windows PowerShell as an Administrator.

      Run the tenantcommand: allowsInstall-Module AzureAD
      If it requests a confirmation, press Y and then Enter.

      Run the selectedcommand: OAuthInstall-Module flowExchangeOnlineManagement
      If it requests a confirmation, press Y and mailboxthen accessEnter.

      pattern. Validate app

      Run registration,the scopes,command: redirectset-executionpolicy URI,unrestricted
      If it requests a confirmation, press Y and consentthen withEnter.

      Run the Microsoftcommand: 365Connect-ExchangeOnline administrator.--Credential $Credential
      The output should be something similar to this:

      Run the command: $app = Get-AzureADServicePrincipal -SearchString "{Application Name}".
      Use the application name from Step 15 of the Setting up Azure section.

      Run the command: New-ServicePrincipal -AppId $app.AppId -ServiceId $app.ObjectId -DisplayName "{Application Name} Service Principal"

      The output should be something similar to this:

      Run the command: Add-MailboxPermission -Identity "<USER ID>" -User $app.ObjectId -AccessRights FullAccess
      The output should be something similar to this:

      Run the command: $startDate = Get-Date

      Run the command:$endDate = $startDate.AddYears(99)

      Run the command: New-AzureADApplicationPasswordCredential -ObjectId {Object ID of Application} -CustomKeyIdentifier "Application Secret" -StartDate $startDate -EndDate $endDate
      Use the Object ID from Step 15 of the Setting up Azure section.

      Example Test Script

      You can use the following example as a test authenticationService flowSuite script. You must perform the above configuration steps first, so you can collect the required parameters: secret key, application id and verifytenant mailid.

      access
      without
      var exposingmailClient tokens= orcreateOAuthMailClient( client"mail@outlook.com", secrets"secretKey", in"applicationID", logs."tenantid");
      mailClient.loginOAuth();
      var Mails = mailClient.getOAuthEmails();
      log(" " + Mails.toString());
      mailClient.logoutOAuth();


      See List of Services Workbench Calls for more details.


      Last updated: SeptemberAugust 29,02, 20262023

      If you have any feedback on this topic, please contact us at documentation@appvance.ai