
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2020 07:53 AM
I have an outbound rest API integration with google g suite. The authentication uses an "Authorization Code" OAuth Profile. I am looking for help on how to pragmatically refresh the OAuth token before running the outbound REST call.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2020 01:52 PM
Hi Jon,
We did something similar with G Suite. We generated a refresh token from Google OAuth 2.0 Playground, stored it as a system property (refreshToken variable below), and then used this code to obtain a new Access token when needed. 'G Suite Admin SDK' being the name of the OAuth Provider in the Application Registries.
// GlideOAuthClientRequest
var clientRequest = new sn_auth.GlideOAuthClientRequest();
clientRequest.setGrantType('refresh_token');
clientRequest.setRefreshToken(refreshToken);
// GlideOAuthClient
var client = new sn_auth.GlideOAuthClient();
// GlideOAuthClientResponse
var tokenResponse = client.requestTokenByRequest('G Suite Admin SDK', clientRequest);
// GlideOAuthToken
var token = tokenResponse.getToken();
var expiresIn = token.getExpiresIn();
var accessToken = token.getAccessToken();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2023 12:41 AM
did you have to do anything to update the Refresh Token when they expired @Amruta12 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2020 01:52 PM
Hi Jon,
We did something similar with G Suite. We generated a refresh token from Google OAuth 2.0 Playground, stored it as a system property (refreshToken variable below), and then used this code to obtain a new Access token when needed. 'G Suite Admin SDK' being the name of the OAuth Provider in the Application Registries.
// GlideOAuthClientRequest
var clientRequest = new sn_auth.GlideOAuthClientRequest();
clientRequest.setGrantType('refresh_token');
clientRequest.setRefreshToken(refreshToken);
// GlideOAuthClient
var client = new sn_auth.GlideOAuthClient();
// GlideOAuthClientResponse
var tokenResponse = client.requestTokenByRequest('G Suite Admin SDK', clientRequest);
// GlideOAuthToken
var token = tokenResponse.getToken();
var expiresIn = token.getExpiresIn();
var accessToken = token.getAccessToken();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 07:35 AM
Robert, this indeed seems the correct way to go, thank you.
Can you provide some guidance on how you obtained the refresh token?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 08:01 AM
Never mind. I think i got it from the playground after authenticating to the playground with my service account

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 02:13 PM
For future reference, I have documented steps to get refresh token here: https://community.servicenow.com/community?id=community_create_article