Skip to Content
Technical Articles
Author's profile photo Vamsi Krishna Chintharlapalli

Step By Step PI\PO Mail Adapter OAuth 2.0 Configuration with Office365


Step By Step PI\PO Mail Adapter OAuth 2.0 Configuration with Office365

  1. Prerequisites
  2. Azure Side setting
  3. PI\PO Mail Adapter side settings

In the current PI Mail adapter, it supports only Basic Authentication in Microsoft Exchange Online. From October 2020 onwards, Microsoft has decided to end the support of Basic Authentication Mode and only support OAuth 2.0 Authentication Mode. For more details refer the below link (published in September 2019) :

https://developer.microsoft.com/en-us/office/blogs/end-of-support-for-basic-authentication-access-to-exchange-online-apis-for-office-365-customers/

Recently, Microsoft has decided to postpone disabling Basic Authentication in Exchange Online for those customers still actively using it until the second half of 2021. In the meantime, Microsoft will continue to disable Basic Authentication for newly created tenants by default.  Starting in October 2020 they will also start to disable Basic Authentication in tenants that have no recorded usage. This means that applications that are using Basic Authentication to connect to Exchange Online might face authentication failures when adopted by a customer who is new to Exchange Online or has not used Basic Authentication applications before.

For more details refer the below link (published in April 2020) :

https://developer.microsoft.com/en-us/office/blogs/deferred-end-of-support-date-for-basic-authentication-in-exchange-online/

 

1.Prerequisites

Microsoft Azure:

  1. If you want to connect PI\PO to Office 365 with OAuth 2.0, you need a directory/tenant in Microsoft Azure Active Directory.
  2. You need a User which has required permissions and subscription in Azure Active Directory( like Administrator or Developer role).
  3. You need a User with a subscription to access the “Mail Account” in office365. Please check whether the mail flow (outgoing \ incoming) is working.

SAP NetWeaver PI\PO :

  1. You need the SAP PI\PO system along with Developer or Admin roles to the PI user. If you have an admin role then, you can make all the necessary configurations, without any issue.
  2. This feature is available in 7.50 SP17 onwards. In this blog, I will be referring to SP21 because caching of refresh and access token feature is enabled from SP21 onwards.
  3. As Office365 is in the cloud, you have to check with your network team whether the port 993(sender side)/587(receiver side) is open. If it is not open then the connectivity will not happen from the Mail adapter.

 2. Azure Side settings:

  1. App Registration
  2. Client Secret
  3. API Permissions
  4. Redirect URL & Copy Endpoint

 

Note: Depending on organisational limits, you may not have access to Azure \ Office365. In this case you can request your Exchange Administrator to setup the below configurations.

You need below parameters to configure OAuth with  PI\PO Mail Adapter.

  • OAuth User ( Office365 user)
  • Client ID
  • Tenant ID
  • Client Secret

 

1)App Registration

a)Open the Microsoft Azure link : https://portal.azure.com/#home

 

b) Select App registrations (or from Manage Azure Active Directory->View-> Manage(on left)-> App registrations.

 

c)Once you open App registrations you can create new registrations or see existing ones.

 

d) Now you can register an application on this page depending upon your account type. In my case I am using a single tenant. Next-> Click on register.

 

e) Once you register you can verify the same, by checking in owned applications under the registered app.

f) Click on your registered application and check the below parameters need for further details :

Application (client) ID   : XXXXXXXXXXXXXXXXXXXXXXX

Object ID                      : XXXXXXXXXXXXXXXXXXXXXXX

Directory (tenant) ID    : XXXXXXXXXXXXXXXXXXXXXXX

 

2) Client Secret

 

a) We need this client secret for OAuth 2.0 authentication(which is also configured in mail adapter communication channels), For this  you need to create a new client secret in your App.

b) Open your application -> Click on “Certificates & Secrets” (on left) -> click on “New Client Secret”.

 

 

 

 

c) Once you provide all the required details, the client secret will be created successfully.

Note: The client secret will only visible during the time of creation. For your usage copy and save it in a secure area. This will be required while configuring the mail channels.

 

3)API Permissions

a) You need to give API permission to authorise the PI Application to access Azure.

b) Open the App registration -> Click on “API Permission”(on left side) -> Click on “Add a Permission” -> Microsoft APIs -> Select Microsoft Graph

c) Depending on the business requirement, you can select the required API permission. In my case-study, as it is a test system, I have selected the below permissions:

 

 

4)Redirect URL&Copy Endpoint

a) In the first step, the generated authorization code will be sent back to the PI application via Redirect URL. Hence we have to define the required redirect URI in Azure. This redirect URI is used internally for PI processing.

b)Open Application -> Click on Redirect URLs in Essentials -> Under “Web” you can add the required redirect URL by clicking on “Add URI”.

 

 

c) Contact your PI/PO developer or consultant while defining the REDIRECT URI in Azure Directory. It should be in-line with the mail adapter channel configuration.

d) Use the channel configuration to fill all the details(like Party, Service and Channel) to create a redirect URI in Azure Portal. Here is the format for your reference :

“https://<host>:<https-port>/ XISOAPAdapter/MessageServlet?channel=<Channel-Name>&party=<Party-Name>&service=<Service-Name>”

e) Once you have completed all the above settings copy the end point details as mentioned below :

 

 

Share the below details to your PI\PO Developer or Consultant.

  • OAuth User( Office365 user)
  • Client ID
  • Tenant ID
  • Client Secret
  • Endpoint URLs

 

 

 

 

3.PI\PO Mail Adapter side settings

 

  1. Sender Side configuration
  2. Receiver Side Configuration

 

PI\PO Mail Adapter will support OAuth 2.0 based authentication(with Office365)on both sender and Receiver side.

Use IMAPS / 993 (port) in the URL.

SMTPS / 587 (port) in the URL.

 

1) Sender Channel configuration

As mentioned earlier you need to get the below parameters to configure them in mail sender adapter communication channel.

  1. URL
  2. OAuth User( Office365 user)
  3. Client ID
  4. Tenant ID
  5. Client Secret

Follow the below steps while configuring the mail sender channel :

a)Configure sender channel as given below :

 

b)Once you save and activate the channel, create Redirect URL as per the below format :

“http://<host>:<port>/ XISOAPAdapter/MessageServlet?channel=<Channel-Name>&party=<Party-Name>&service=<Service-Name>”

Provide this to Azure administrator to use while adding Redirect URl ( Please      Refer: 2. Azure Side settings ->4) Redirect URL & Copy Endpoint)

You have to encode the Redirect URI  else you will face “URL specified request does not match” error while generating the refresh token.

c)Once the Redirect URI is updated in the Azure portal, proceed to generate tokens(refresh/access) with the below URL

“https://login.microsoftonline.com/<Tenant-Id>/oauth2/v2.0/authorize?client_id=<Client-Id>&response_type=code&redirect_uri=<Redirect-URI>&scope=<Scope>”

Required Scope for Sender side : “https://outlook.office365.com/IMAP.AccessAsUser.All”

d) Once you execute the above URL, Check the result in the browser itself.

 

Note: These tokens are generated with the help of authorization code, which is generated while executing the above URL(in the background). After successful generation of the tokens, they will be stored in cache. While executing the URL, you will be required to provide the login details of Azure(First) and  PI/PO (next).

 

 

2)Receiver Side Configuration

Follow the same steps(as mentioned for Sender side Configuration)  and use SMTP protocol to send mails to Office365 via OAuth 2.0 authentication.

Required Scope for Receiver side: https://outlook.office365.com/SMTP.Send

 

The above steps will help you to configure PI\PO Mail Adapter with OAuth 2.0 authentication with Office365.

You can refer to the SAP Note & documentation below for more information.

Note: 3021526 , 2928726

SAP NetWeaver 7.5 – SAP Help Portal

 

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.