John Zhang1
Kilo Patron
Kilo Patron

OAuth 2.0 lets users access instance resources through external clients by obtaining a token rather than by entering login credentials with each resource request.

 

The propose of this blog is to show how to trigger Rest integration secured by OAuth 2.0 using the Action Designer of Flow Designer.  I am going to introduce two way how trigger Rest Integration using OAuth token:   

 

1) Action Script;

2) Integration hub -Rest integration configuration. 

 

Pre-requirement

For Rest integration configuration in the Action Designer, which requires the Integration hub plugins.   I am going to perform this OAuth Rest integration using two ServiceNow Instances: Instance A (source) and Instance B (target).

 

OAuth 2 Client Register (Instance B)

First step is located to Application Registry (see blow) through Navigation Filter in Instance B. 

JohnZhang1_1-1691793804245.png

Click "New" to create new record and fill "Name" filed and then click "Save".   Three fields: Client ID, Client Secret and Redirect URL will auto populated.  Please write down three field value for next step

JohnZhang1_2-1691794359026.png

Create OAuth 2 Provider Record 

Located to Application Registry (see blow) through Navigation Filter in Instance A to create new OAuth provider record blow by filling the following fields:

JohnZhang1_3-1691794627319.png

Create Outbound Rest Message

In instance A, create Outbound Rest Message blow-all fields highlighted by yellow.  After you pick OAuth 2.0 in Authentication type field, please select OAuth profile value created from the above step and save this record.

JohnZhang1_6-1691795219992.png

 

Test OAuth 2 token

In Rest message you created in instance A, you click "Get OAuth Token" in related link and then another token window is popup.  When you click "Allow" button, OAuth will allow you connect to instance B

JohnZhang1_0-1691795869826.png

 

So far we have competed the configuration for both OAuth and Rest integration so next we are going to use the Action Designer of Flow Designer to configure and  trigger the outbound Rest message to connect from Instance A to Instance B using OAuth 2 token security approach.    

 

Action Script (Approach 1)

This approach is using the Action Script to call the Outbound Rest Message -Create OAuth Request created early rather than using REST configuration as a part of the Integration hub. 

Step 1-Define new Flow Action in Action Designer by add "Script" action

JohnZhang1_0-1691861776451.png

 

Steps 2 -Copy the script from Rest Message previously defined

JohnZhang1_1-1691862036848.png

Step 3 - Paste the copied script into script action and defined Output variable - 

JohnZhang1_2-1691862176629.png

Steps 4- Define Outputs and assigned the output variable -resResponse

JohnZhang1_3-1691862456713.png

Step 5 - Test your action to verify the results

JohnZhang1_4-1691862632113.png

You would find the Outbound Rest Integration configured by OAuth 2 is successfully called through the Action script of Action Designer from response output.    

 

Rest Integration Configuration (Approach 2)

This approach requires the Integration hub plugins activation before we can use the Rest action in Action designer.

Step 1 - Activate Integration hub plugins

Step 2 - Define new Flow Action in Action Designer by add "REST" action

JohnZhang1_0-1691863554856.png

 

Step 3 - Define your connection to Instance B

You need to create Rest user access account to define the initial connection to the instance B

JohnZhang1_1-1691865395999.png

Step 4-Configure REST like blow:

JohnZhang1_2-1691865481914.png

 

Step 5 - Define output

 

Step 6 - Test your action to verify the results

JohnZhang1_0-1691864369587.png

 

Summary

I have demoed two approaches: 1) Action Script; 2) Action Rest to configure and trigger the Outbound Rest integration secured by OAuth 2 through the Action Designer.   You can use either the Action REST (Integration hub plugin required) and Action Script (no additional requirement).   This blog will strandline the Rest integration with OAuth implementation through Flow Designer so you can easily apply your flow to any ServiceNow Rest integration with OAuth secured.

 

If you like my post, please mark it as useful 

4 Comments