The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Issue with Auto Refresh Token

deepikamara
Tera Contributor

Hi All,

We are performing an integration using a Spoke in ServiceNow and have configured the oauth_2_0_credentials table to store the OAuth 2.0 credentials. The initial access token was successfully generated, and we set the refresh token lifespan to 8,640,000 seconds in the Application Registry.

However, we are encountering an issue:
Before the access token's expected expiry time, the integration fails in Flow Designer with an authentication error. Once we manually refresh the token, the flow starts working again as expected. Can you please help us.

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@deepikamara 

So you generate fresh access token each time using script and then pass that token to Flow step in actual API call

refer below links on how to get token from script

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

Hi @Ankur Bawiskar ,

Could you please help me understand why my access token is not working even though it hasn't yet reached its expiry date?

@deepikamara 

refresh token has long expiration, access token has usually 30mins.

It's already recommended to generate the access token using script before consuming the actual endpoint although you are calling the actual endpoint multiple times in 30mins and the access token will be the same for that 30mins.

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