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

Generate a new OAuth Refresh token once it is expired

Sharan Ellendul
Tera Contributor

Hi,

 

We are integrating ServiceNow with a third party tool. That third party tool wants to pull data from ServiceNow. So we have created a OAuth registry for Authentication purpose. The other tool uses only Client ID, Client Secret and Refresh token to generate Access token. Now for every certain period of time refresh token expires. How to automatically generate new Refresh token within the same ServiceNow instance itself, so that we can send that Refresh token to that tool via email from ServiceNow?

 

Thanks in Advance

Sharan

6 REPLIES 6

vishakhayadav24
Tera Guru

Hi @Sharan Ellendul 

 

Write a schedule job for the same as access token and refresh token are stored in oauth_credential table.

schedule job would run just before the Refresh token expires and regenerate the refresh token.

below is the article having script:

Script to retrieve Access and Refresh tokens using GlideOAuthClient libraries

and in the same scheduled job you can send them the new token to the third party tool.

 

Thank you!!

Vishakha Yadav

 

Hi @vishakhayadav24 ,

 

Should we create both External Client record and OAuth Provider record in the registry?

I have tried just using External Client Registry record and created a Entity profile. Used that profile in the script. This is the error we got.

SharanEllendul_0-1720011831224.png

 

So there is another case which we have tried, which is creating both External client registry record and using those client ID and client Secret, we have created a new OAuth provider record and used that record in script. Then it was generating refresh token and access token. But it was creating 4 records in manage credentials table 2 each (refresh token and access token) for Client Record and Provider record. Could you help in clarifying this?

 

Thanks,