Skip to main content

Microsoft mailbox as a data source for ERM [OAuth 2]

The process is divided into 3 dependent parts:

  • Creating the Microsoft Azure App
  • Authentication through Terminal
  • Creating the Data Source in JeraSoft Billing

Creating the Microsoft Azure App​

  1. Login to https://portal.azure.com with your Microsoft credentials, and go to Azure Active Directory.

    Azure Active Directory

  2. Go to the App Registrations page.

    App Registrations

  3. Click the New Registration button.

    New Registration

  4. Register a new application using the settings from the screenshot below:

    Register a new application

  5. Save the Application (client) ID and Directory (tenant) ID values from the Overview tab of the freshly created app.

    Overview tab

  6. Allow public client flows from the Authentication tab of your application:

    Authentication tab

  7. Now, you have to add some permissions to your application - it should be IMAP.AccessAsUser.All (to be able to login to your mailbox) and offline_access (to be able to refresh token on Email Rates Manager’s demand).

    API permissions 1

    API permissions 2

    API permissions 3

    API permissions 4

    As a result, you should have 2 permissions added to your application:

    Added permissions

Authentication through Terminal​

  1. Download the obtain_refresh_token.py script to your computer.
  2. Open the terminal, go to the directory where the downloaded script is located (using cd command), and execute the following command, which will install the needed for authentication python package:
pip3 install msal
  1. Next, run the script itself using the following command:
python3 obtain_refresh_token.py <CLIENT_ID> <TENANT_ID>

where CLIENT_ID is an Application (Client) ID, TENANT_ID - Directory (Tenant) ID. You obtained these values during the previous steps.

As a result, you should see the message like in the screenshot below. Go to https://microsoft.com/devicelogin and enter the code you see in the terminal. Next, go through the authentication process and grant the required permission to the application.

danger

WARNING: Do not close the terminal during the authentication process.

Console output 1

Enter code

  1. If the authentication process was completed successfully, you will see the "success" message in the terminal. Please save the refresh_token value. You will need it to create the Data Source in JeraSoft Billing later.

    Console output 2

Creating the Data Source in JeraSoft Billing​

  1. Log in to JeraSoft Billing, open Integration → Data Sources tab, and click the Add Source button;
  2. Choose the "IMAP Microsoft [OAuth2]" connection type and fill in the Name, Login, Client ID, Tenant ID, and Refresh Token fields. The Host field is pre-filled with the "outlook.office365.com" value, and you should not change it.
  3. Click Apply.

Once the steps above are completed, you can choose the freshly created Data Source as a source for Automatic Email Import in the Rate Tables settings.