How to configure refresh token so that it does not expire

karl_cheng
Mega Contributor

Hi, I am setting up oauth on an instance, and have created a refresh token.  The documentation says that the refresh token expires in 100 days by default, and I can change it on the console.  However, I would like the token to never expire.  Is there a way to do that (would setting a value of -1 do the trick?)   

 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Karl,

I don't think system would allow so because of the OAuth functionality. It would have some life span.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Karl,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

ARG645
Tera Guru

A refresh token has to be expired according to the physics of OAuth. 

If you dont want a refresh token to be expired (which i dont think is a good idea). 

Go to the table oauth_credential OR search for the Module Manage Tokens under System OAuth. Once you are in this table you should find a record related to your refresh token, in this record you can manipulate the Expires Field . You can probably put a Business Rule/Scheduled Job that keeps extending the value in the Expires field. This way your refresh token doesn't expire. 

find_real_file.png

 

 

Is it possible to set expires in 3650 days (say 10 years) for a refresh token when generating the tokens?

Here I am using following python code to generate tokens

post_data = {
    'grant_type': 'authorization_code',
    'code': <code>,
    'redirect_uri': '<redirect_url>',
    'scope': 'useraccount'
    # Any query parameter to set expiry date?
}
auth = base64.b64encode('<client_id>:<client_secret>')
headers = {'Authorization': 'Basic {}'.format(auth)}
resp = requests.post('https://instance.service-now.com/oauth_token.do', data=post_data, headers=headers)

 In the post_data, are there any query parameter to set expiry date?  or any other way to set expiry date are also welcomed except manually setting in application registry.