How to automatically use Oauth refresh token in outbound REST message?

Mattias1
Kilo Explorer

I've set up OAuth integration with a custom third-party OAuth provider. This part works fine. I am able to get the OAuth tokens. Then I use this OAuth integration together with an outbound REST message, and that also works fine as long as I have first obtained the OAuth tokens.

Here comes the problem, the access_token I get is only valid for 5 minutes and after that I have to repeat the "Get OAuth tokens" again to continue using the outbound REST message. I also get a refresh token that is valid for 3600 seconds. But I don't know how to use this token for anything.

Is it possible to automatically use the refresh token to obtain a new valid access token if the outbound REST message discovers that the access token is no longer valid? Or can I create a cron job that refreshes the access token automatically every 5 minutes? Or does someone have suggestions of other ways of solving this? Unfortunately I can't do anything about the 5 minute validity window.

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Mattias 

You can use script to obtain the refresh and access token from script

refer below links

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

Regards
Ankur

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

Hi when I'm trying to add a input in the Azure AD add user to group in custom activity I'm getting this error. we need to add the users into group of azure ad.

 

find_real_file.png

as I have given the sys_id of the user and group id from client application

 

 

 

 

 

find_real_file.png