OAuth 2.0 bearer -- First log-in by User/Password

Vincenzo Basile
Tera Expert

Hi,
I have some problem with an OAuth 2.0 connection activable by user/password on the first step to obtain the 2 token (auth / refresh),
used to allow the access of a webservice available on a third parties system.

Essentially, after the "Get OAuth Token" (available on the rest message), the servicenow instance store the 2 tokens in the auth_credential and all work correctly for days...

(NOTE:
The webservice is used every 30 minutes and I see that the refresh token is updated every time that the authetication token is recalculated.
So I think that it could be work always)

The problem is that after an undefined time, I receive an error about the recalculation of the authentication token by the refresh token.
The error report that the Refresh token is not valid.

I don't know why it happen and the third parties support are not able to help me, because a simple workaround is the re-using of the credentials for obtain a new Refresh Token.

So, I need to reinsert the credential by the "Get OAuth Token" (available on the rest message) every time and without know when do this...

My idea is to atomatize it by the code reported on this KB:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0791131


The idea is to use it on the "OAuth API Script",
the problem that I have now is related to the use of "oauthContext" (that is an object GlideOAuthRequestContext)
After a deep research I undetand that by "oauthContext.getOAuthProfile()" I can identify the oauth_entry_profile.
So now I have :
- oauth_entry
- oauth_entry_profile

But at the end to use the code reported on the KB I need also to have "oauth_requesto_profile"

I'm quite sure that this information is stored on the "oauthContext", but I don't found any information about the methods availabe on this object, or how I can identify the oauth_requesto_profile by the OAuth API Script.

Can samebody help me to identify how I can obtain the "oauth_requesto_profile" ?

 

1 REPLY 1

Meloper
Kilo Sage

Hi, try to set the Value of this Property to 15
glide.rest.outbound.oauth_token_expired_threshold