How can we get the access Token for OAuth2.0 as grant type of client credentials

ashokbodaga
Tera Contributor

Hi ,

 

I have a requirement like I created a OAuth provider as a Grant type of "Client credentials". How can we get the Access token and refresh token  for every 15 minutes to make the connection active. I had referred few posts as a grant type of Resource owner password credentials.

 

Can some one help me how can I achieve this.

 

Thank you.

2 REPLIES 2

-O-
Kilo Patron

Have you looked into the GlideOAuthToken API?

E.g, if you have defined an OAuth 2.0 Credentials [oauth_2_0_credentials] record for an OAuth client (with a grant type of Client Credentials), you could write something like:

var oAuthClient = new sn_auth.GlideOAuthClient();
var oauth20Credentials = '<Sys ID of the OAuth 2.0 Credentials [oauth_2_0_credentials] record>';
var oauthEntityProfile = 'value of field OAuth Entity Profile [oauth_entity_profile] of the same OAuth 2.0 Credentials [oauth_2_0_credentials] record';
var token = oAuthClient.getToken(oauth20Credentials, oauthEntityProfile);

gs.debug(token.getAccessToken());