Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help need with OAuth 2.0

KrithikaV
Tera Expert

Hi,

I am trying to get OAuth credentials set up to connect to a third party application using grant type : client_credentials.

When using Postman, I get the following response:

{
    "tokenType": "Bearer",
    "expiresIn": 86399,
    "authToken": "eyJhbGciO........EQ"
}

In the ServiceNow's OAuth 2.0 Credentials screen, when I click on 'Get OAuth Token' link, I get the following error: 

 

OAuth flow failed. Verify the configurations and try again. Error detail:invalid_request, Missing parameters: access_token

 

I tried to run the following in the background script:

 

var oAuthClient = new GlideOAuthClient();
var params = {grant_type:"client_credentials"}; 
var json = new global.JSON();
var text = json.encode(params);

var tokenResponse = oAuthClient.requestToken('My Provider Profile', text);
accessTokenResponse = tokenResponse.getBody();
gs.log('Token response: ' + JSON.parse(accessTokenResponse).authToken);

 

I get the following response:

OAuthProblemException{error='invalid_request', description='Missing parameters: access_token', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}
*** Script: Token response: eyJhbGciOiJIUzI1N.......AAgwpv0

 

The third party response does not contain the json parameter 'access_token' but has 'authToken' instead. I tried experimenting with the OAuth API Script : OAuthConsumerSupport by overriding the initiateCCTokenFlow method, but could not achieve anything useful.

 

Kindly help me with this.

0 REPLIES 0