Script for automatically updating Managed Oauth tokens in oauth_credential

Andrei Radules1
Giga Contributor

Hello,

I am trying to automatize the refreshing of Oauth tokens that I use in the REST Messages, so I don't have to manually trigger it once the refresh token expires.

I know the Access and Refresh token is stored in the oauth_credential. Can someone help me find a script that checks if they expire and if they do generate a new one ?

Thank you !

19 REPLIES 19

One note would be that the my instance requests a token from another servicenow instance

Apologies for the incorrect analysis. I created this on the impression that you are trying to generate token from a 3rd party url.

Forthe questions

1) regarding url: the mentioned one was I provided:https://instance/oauth2/token. I will come back to you regarding service now instance if I find anything.

2) on http header Authorization: Basic (encoded clientid:clientsecret) This way it will handle the basic authentication(client id and secret will be the credentials,authentication is client credentials type)

Please check this answered link:https://community.servicenow.com/community?id=community_question&sys_id=cfdf07a5dbdcdbc01dcaf3231f96193d&view_source=searchResult

Hi,

Did it work?

hello,

 

Unfortunately still not working, not sure what I am not doing properly, still getting the bad username password 401 error.