Refresh oauth token for outbound rest call

Jon Ulrich
Kilo Guru

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.

1 ACCEPTED SOLUTION

Robert Beeman
Kilo Sage

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();

View solution in original post

10 REPLIES 10

 

Hi @Robert Beeman ,

I doing something similar with Workday. I am facing challenges to understand where the above piece of code to get the access token will reside. Will it be it in the OAuth provider under OAuth API script?

Also, is it the complete code or any modifications required?

- I have OAuth provider ready

- REST Message is also ready. Just need to have the access token available for REST MESSAGE to get the required data.

Could you please help?

Regards,

Nirmal