How to configure Outbound Rest Message with oAuth 2.0 - Resource Owner Password Credentials

Meloper
Kilo Sage

Hi,

i have Username, Password, ClientID and Client Secret to get a Token, with that Token i need to call a second Endpoint to get the Values.
Instance is on Yokohama Patch 2.

If i create the OAUTH2 Provider Record and the matching Credentials Rercord. Im able to get the Token over the Midsever if write Username and Password in that Pop Up Window.

So after this i created a Rest Message with a GET methode and the Endpoints which holds the Datas that i need.

But i cant connect.
I tried with a manual header and copy and paste the Values (token)
Also in a Script i can click manual on "get Oauth token"
What are the Steps need to be done to have a REST Message, connected to that OAUTH2 Profil which gets the Token and calls the Rest Message automatically? 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Meloper 

From wherever you are calling that Rest Message do this

1) use script to get the Access token

2) then use that access token in your actual endpoint and include that in header

check these links

Two way to configure OAuth 2.0 -Outbound Rest integration in Action Designer  -> good article

Configure a REST message with OAuth 

Setting oAuth profile not working if rest message does not have oAuth preset 

Google Calendar Integration with ServiceNow 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Meloper 

check this link for recent discussion where I participated

How to make access token refreshed for every an hour? 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur, thanks, that was quick but didn't solve my Question.

1. i am using the spatial password grant type.
Likewise, I also want to use the OAUTH profiles and not write an extra rest message like you did in https://www.servicenow.com/community/api-insights-forum/how-to-make-access-token-refreshed-for-every....

2. how do I save the username and password so that the token can be fetched automatically?
Hopefully I only have to click on get oauth token to test
I would hope that if I use the REST message, I don't have to do all that "stuff".
Where do I store the username and password?

@Meloper 

You can store username and password in system properties

To store password you can use password type system property.

Before you make actual 2nd API call use script to generate the token

OR

you can use Credentials, Connections Alias etc and see below link on how to setup

Connections, Credentials, Aliases and OAuth 

You can use script to obtain the refresh and access token from script, script will vary based on grant type somewhat

refer below links

OAuth2.0: Get new Access Token from existing Refresh Token

How to Setup OAuth2 authentication for outbound RESTMessageV2 integrations

OAuth : Script to Automate Token Request

How to generate the access token once it is expired from Business Rule?

How to get Auth Token using script when grant type is Authorization code

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader