
- 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
06-29-2020 07:59 AM
Hi ,
Here are links which will help you.
If it helps,Please mark ✅ Correct and 👍 Helpful.
Warm Regards,
Milind

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 12:06 PM
None of these explain how to use an "Authorization Code" OAuth Profile, but a username/password profile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:17 AM
Hi,
to be on safer side it is recommended generating the OAuth token before consuming actual endpoint first to avoid the expiration time of access token
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2021 04:53 AM
Hi Ankur
In Paris version, I observed that when we execute REST Message with OAUTH authentication, it automatically updates the token (checking under Manage Tokens). This works without writing code for checking if token expired and then getting refresh token. So is having REST Message with OAUTH profile association good enough?
I did not find any documentation around it.
Thank you