The CreatorCon Call for Content is officially open! Get started here.

OAuth token refresh question

Tomko
Tera Expert

I am building my first integration (using REST and OAuth), and everything is working well, except that the OAuth token for the external system keeps expiring (it's set to 30 minutes).  

I can refresh it manually by going to the REST Message, and using the Get Token UI Action, but obviously that isn't the real solution.

How can I refresh the token automatically (I am calling the REST Messages via business rule)? 

7 REPLIES 7

Alikutty A
Tera Sage

Hello,

Your script will need to validate if the auth token has expired and then automatically renew it.

Please refer to these posts covering the topic in different ways

https://community.servicenow.com/community?id=community_question&sys_id=c459e6a4db9ee30011762183ca96193e&view_source=searchResult

https://community.servicenow.com/community?id=community_question&sys_id=5b544769dbd8dbc01dcaf3231f961937&view_source=searchResult

 

Tomko
Tera Expert

Thank you for the reply.  Let me back up a bit, because I am starting to question my approach.

I need to integrate with Salesforce.  My ServiceNow users do not have a Salesforce account, so I need to be able to use a service account to authenticate to Salesforce.  I'd originally set up the Oauth provider using an Authorization Code grant type.  This works great (the refresh issue non-withstanding).

However, the token is tied to my ServiceNow user.

Should I be approaching this differently?  Since my ServiceNow users won't be able to log into Salesforce, should I be using a different grant type?

A generic SN ID would suffice who can authenticate on behalf of all users. You can setup a temp user using a SYS property and use this ID to access tokens.

Hi Tomko,

 

Did you find the solution for this. I have same the requirement, please let me know if you were successful with the oAuth intergration.