Some OAuth providers require additional parameters to be sent in addition to standard parameters (grant_type,username, password , client_id , client_secret ) to issue access token and refresh token . This article explains how to send any additional parameters from the script .


0) Create the OAuth Provider record in ServiceNow instance with all the required values .

1) In the script , create a params string and include any additional parameters that the OAuth Provider expects .

2) For example if a parameter called "resource" needs to be sent , include it the the params variable .

3) Below is a sample code .

var oAuthClient = new sn_auth.GlideOAuthClient(); 
var requestor_context = 'test'; 
var requestor_id = ''; 
var oauth_profile_id = '<sys_od_of_oauth_profile>'; 

var params = {grant_type:'password', username:'', password:'pa$$word', resource:'123-123-123', oauth_requestor_context:requestor_context, oauth_requestor:requestor_id, oauth_provider_profile:oauth_profile_id}; 

var json = new global.JSON(); 
var text = json.encode(params); 
var tokenResponse = oAuthClient.requestToken('<OAuth_Profile_Name>', text); 
var token = tokenResponse.getToken(); 
var access_token = token.getAccessToken() ; 

gs.log("AccessToken:" + access_token); 
gs.log("AccessTokenExpiresIn:" + token.getExpiresIn()); 
gs.log(" RefreshToken:" + token.getRefreshToken());

Applicable Versions

All versions .

Article Information

Last Updated:2019-08-02 20:49:09