- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 07:49 AM
First, I have created a OAuth Profile for Google Cloud in the Application Registry using the 'Connect to a third party OAuth Profile'. The Profile created is as follows.
I am using the OAuth Profile in the REST Messages to Various Calls such as Create VM,Turn Off Vm,Turn On VM etc., when I am using the OAuth Profile it shows the following message every time that 'OAuth Access or Refresh tokens are not available. Verify the OAuth configuration and click the 'Get OAuth Token' link below to request a new token.'
Everytime I query a REST message it shows this and I need to Click on Get OAuth Token to get the Token. The Validity of the token lasts for only an hour after that I need to refresh it again by clicking on the Get OAuth Token.
I need to know is there any way by Scripting or any other method to get the OAuth Token without Clicking the Get OAuth Token and also token lasts for a longer time.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 08:39 AM
Hi Aashish,
The key is you need to get an 'offline' token so it lasts as long as your refresh token lifespan indicates.
josh.nerius covered this on the 9-23-2016 edition of Live Coding Happy Hour. I had to implement it myself recently.
Watch this video. He starts somewhere around 40:00.
ServiceNow Live Coding Happy Hour for 2016-09-30 - OAuth Part 2 - YouTube
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2017 09:08 PM
Hello Rajeev,
How do you re-generate the Refresh Token before it expires? Doesn't it require user consent?
Thanks,
Probir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 10:16 AM
When you generate your auth token , you get refresh token and expiration date time of refresh token as well. So you can trigger event schedule to run before the expiry of your refresh token. Take the below example where I schedule a event 1200 seconds before the expiry of refresh token.
#1
var gdt = new GlideDateTime();
gdt.setDisplayValue(current.u_expiry_date.getDisplayValue());
gdt.addSeconds(-1200);
if(current.u_expiry_date != '' && (current.u_expiry_date != previous.u_expiry_date))
{
gs.eventQueueScheduled("RefreshToken.Trigger", current, gs.getUserID(), gs.getUserName(),gdt);
}
#2
and then you can write your code under "Events" --> Script actions (which will trigger when event RefreshToken.Trigger is trigerred) to generate the access token again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 10:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 01:30 AM
Hello,
Could you please tell me how the refreshToken function looks like in your event script?
I am trying to implement a similar thing.
Thank you !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 12:29 AM
Hello,
Can you please explain to me a bit better how you can use this code to refresh the token/ refresh token ?
Thank you !