Refreshing OAuth for Google Cloud Using Script?

aashishdasari
Tera Expert

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.

find_real_file.png

find_real_file.png

find_real_file.png

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.'

find_real_file.png

find_real_file.png

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.

find_real_file.png

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.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

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


View solution in original post

16 REPLIES 16

The ACL on the oauth_credential table is causing this issue. Try adding a read ACL on the table and provide the role who needs this access to call and you should be good to go.

Anton Maksymch1
Giga Contributor

This one solution helps, in my case here.


HANDLING A NON-EXPIRING TOKEN

I mentioned that I’d show you how to handle the non-expiring token sent by Bit.ly, but didn’t get around to it during the broadcast.

To accomplish this, we need to add a single line to the postProcessAccessToken method in our custom OAuthBitlyHandler Script Include:

// Manually set the expire time to 1 year in seconds (60 * 60 * 24 * 365) paramMap.put(bexpires_in’, b31536000’);

In this example, I’ve set the expiration time to 1 year, but you should set this to whatever value makes sense for you and your password rotation schedule (you should go and regenerate this periodically for security reasons, even if the the API doesn’t enforce token rotation).