Setting up OAuth 2.0 compliant email listener in Integration Server using Microsoft Azure Active Directory (Azure AD)
Tags: oauth2, integration, azure, tutorial
Published: 2021-08-11 12:59:58

---
title: Setting up OAuth 2.0 compliant email listener in Integration Server using Microsoft Azure Active Directory (Azure AD)
published: true
date: 2021-03-17 11:42:55 UTC
tags: #oauth2, #integration, #azure, #tutorial
canonical_url: https://tech.forums.softwareag.com/t/setting-up-oauth-2-0-compliant-email-listener-in-integration-server-using-microsoft-azure-active-directory-azure-ad/239699/1
---

## Concepts

Typically, applications access Microsoft Exchange Server with basic authentication, which relies on sending usernames and passwords that are often saved on the device, increasing the risk of attackers capturing users’ credentials.

Due to such security risks, Microsoft has announced the end of support for basic authentication-based access to Exchange Servers. Instead of basic authentication, Microsoft encourages customers to use OAuth 2.0-based authentication in all applications that access Exchange Servers. For more information about Microsoft’s announcement, see [Exchange Online deprecating Basic Authentication - Microsoft Lifecycle | Microsoft Docs](https://docs.microsoft.com/en-us/lifecycle/announcements/exchange-online-basic-auth-deprecated)

The benefits of implementing OAuth-based authentication for your application are:

- Applications can delegate the authorization of users to an OAuth server.
- Since access to resources in OAuth is based on an access token, it can be issued and revoked as required.
- Limit an application’s access to resources through an access token.

In an OAuth framework, there are three active roles. A client application, an authorization server, and a resource server. The authorization server is responsible for validating the user’s identity, granting and revoking access to resources, and issuing access tokens to the client application based on the supported grant type and in turn, the client application must send the access token to the authorization server in its requests for resources.

To use Integration Server to access or send emails through Microsoft Exchange Server, you must register the Integration Server instance as an OAuth client on Microsoft’s Azure portal for OAuth 2.0 compliance.

Since Integration Server uses the Authorization Code grant type, the Exchange Server expects an authorization code in the request for an access token.

Registering Integration Server on Microsoft’s Azure portal provides the OAuth credentials (Client ID, Tenant ID, and Client Secret) that Integration Server requires to request an authorization code from the Azure AD. Integration Server can then use the authorization code to acquire an access token from the Azure AD. Azure AD uses the access token to authenticate Integration Server requests and grant them access to the required resources on the Exchange Server.

In this setup, Integration Server is the client application while Azure AD is the authorization server and Microsoft Exchange Server is the resource server.

## Description

In this article, you will learn to register Integration Server as an OAuth client in Azure AD.  
As part of the registration process, you will:

- Obtain the Application (client) ID, Directory (tenant) ID, and create a Client Secret. All these credentials are required to obtain access and refresh tokens from Azure AD.
- Configure API permissions for Integration Server to access a mailbox on a Microsoft Exchange Server using the Microsoft Graph API.

After registering Integration Server as an application on Azure AD portal, you can:

- Create an OAuth 2.0 compliant e-mail port in Integration Server to access a mailbox on a Microsoft Exchange Server.
- Configure Integration Server to send emails through a Microsoft Exchange Server using OAuth 2.0 compliant SMTP outbound requests.

## Actors

- Microsoft Azure Active Directory (Azure AD) portal allows you to register Integration Server as an OAuth client and behaves as the authorization server.
- Microsoft Exchange Server works as the Resource (Mail) server.
- Integration Server is the OAuth client.

## Pre-conditions

- An Azure account with an active subscription.
- An Azure AD tenant that has the Global Administrator role.

For more information, see [Quickstart: Register an application with the Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app)

> **Important** : The OAuth authentication type is supported only for e-mail listeners associated with an IMAP server. By default, this authentication type is available in Integration Server, version 10.7. To use this authentication type in version 10.3, install 10.3 Core Fix 14 and in 10.5, install 10.5 Core Fix 7.

## Basic Flow

1. Log in to the [Azure Portal.](https://portal.azure.com/)
2. Click ![Azure_Menu](https://aws1.discourse-cdn.com/techcommunity/original/2X/2/21183829fe5c1bc084aec7262b4be72859b612b2.png) > **Azure Active Directory** > **App registrations** , and then **New registration**.
![App_New_Registration](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/a/aa4e86ba053489758684e28aeddb24ec553f2222_2_689x500.png)
3. On the ‘ _Register an application’_ page, enter the necessary information and click **Register**. For more information, see [Register an application](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app). On successful registration, the Application (client) ID and Directory (tenant) ID are generated.
**Note** : The **Redirect URI** that you enter during registration is the URL that Azure AD must use to send authentication responses to Integration Server.
Enter the redirect URL in the following format:  
`https://{ISHostName}:{port}/WmRoot/security-oauth-get-authcode.dsp`
![App_Register](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/d/dc56de5067ccc0f183c2c221a6f635624c2d135f_2_670x499.png)
4. You can use the Microsoft Graph API to access a mailbox on an Exchange Server. To assign access privileges to Integration Server, configure API permissions as follows:
    1. Click **View API Permissions** to view the available API permissions. You might see the `User.Read` permission assigned by default. You can either retain or remove the permission and continue to configure the required permissions as follows: 
    2. Click **Add a permission** > **Microsoft Graph API** > **Delegated permissions**.
    3. In the **Select Permissions** field, enter the first few letters of one of the following permissions, and select the permission once it appears in the list. Similarly, select the other permissions. 
      - `IMAP.AccessAsUser.All`
      - `offline_access`
      - `SMTP.Send`
    4. Click **Add Permissions**.
    5. Click **Grant admin consent**.
![View_API_Permissions](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/d/d360e299ae313e99cdd77298d4874e584b436822_2_690x363.png)
![App_Add_Permissions](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/2/2f19f2a3d64664469900d7a86481f677d5645baf_2_690x286.png)
![App_Grant_Admin_Consent](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/b/b3ef3460d872b8c8f0b20e3bcf58d2fe31c3791a_2_690x208.png)
5. Configure a client secret, a unique string that Integration Server uses to request an access token. Perform the following steps:
  1. Go to **Certificates and secrets** > **Client secrets, and then click New client secret**.
  2. In the Description field, enter a name to identify the client secret.
  3. Select when the client secret expires and then click **Add**.
> **Important** : Note the client secret before you leave the page.

## What next?

With the following details, set up an OAuth 2.0 compliant e-mail port using Integration Server Administrator. Once the port is created, Integration Server programmatically acquires the authorization code, followed by access and refresh tokens from the Azure AD.

  - **Auth URL** : `https://login.microsoftonline.com/<TenantID>/oauth2/authorize`

  - **Client ID** : The application (Client) ID obtained on completing **step 3**.

  - **Client Secret** : The string that you generated on completing **step 5**.

  - **Scope** : `offline_access` `https://outlook.office365.com/IMAP.AccessAsUser.All` `https://outlook.office365.com/SMTP.Send`

  - **Access Token URL** : `https://login.microsoftonline.com/<TenantID>/oauth2/token`

  - **Redirect URL** : The value that you entered for Redirect URI in **step 3**.

The following image shows a sample email client configuration with OAuth credentials.

![image](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/1/1e9d404cfc09c08969ed887d2d6a87273264fefa_2_463x500.png)

On saving the changes, the following screen will appear:

![IS_Email_Port_OAuth_Config_Saved](https://aws1.discourse-cdn.com/techcommunity/optimized/2X/3/3e9720e7f426787d7a5004897fbd8ed9f7cfa5a9_2_655x500.png)

## Using OAuth 2.0 authentication in the built-in SMTP services

To send outbound SMTP requests from Integration Server built-in services using the OAuth mechanism, perform the following steps:

  1. Obtain the authorization code manually by sending a request through a browser in the following format:
`https://login.microsoftonline.com/<TenantID>/oauth2/authorize?response_type=code&prompt=login&redirect_uri=http://host:{port}/WmRoot/security-oauth-get-authcode.dsp&client_id= <clientID>&scope=<scope>`
Here, `response_type` is set to `code` to inform the OAuth server that Integration Server expects an authorization code as the response at the mentioned `redirect_uri`.
The response from the OAuth server would look like this:
`http://host:{port}/WmRoot/security-oauth-get-authcode.dsp?code=AQABAAIAAAAm-xxxx&session_state=yyyy`
Here, the value of `code` is the authorization code.
  2. Run the `pub.client.oauth:getExternalAccessToken` service with the `grant_type` as `authorization_code` and `code` as the authorization code received in the previous step, along with other input parameters as shown in the following image:
![BIS_getExternalAccessToken](https://aws1.discourse-cdn.com/techcommunity/original/2X/b/b2ed0516c8944d1107e705c6d96ed00c267c019d.png)
  3. Run the `pub.client:smtp service` using the output of the previous step as shown in the following image:
![BIS_Oauth_SMTP_Service](https://aws1.discourse-cdn.com/techcommunity/original/2X/7/7eef0065af9dffaa19868dc7cf3e0bcffcf431d5.png)

[Read full topic](https://tech.forums.softwareag.com/t/setting-up-oauth-2-0-compliant-email-listener-in-integration-server-using-microsoft-azure-active-directory-azure-ad/239699/1)