OAuth authentication for Inbound

guestee
Tera Contributor

I have a script include which calls out of box Service Catalog API (order_now), I want to use oauth authentication in the script to get the token.

I have created OAuth Provider record in application registry and used it in the background script to generate OAuth token, throws error.

Pls help

var oAuthClient = new sn_auth.GlideOAuthClient();
username = 'admin'; 
password = '123'; 
params = {
grant_type: "password",
username: username,
password: password
};
var json = new JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('oauth_client1', text); // oauth_client1 is the OAuth provider record in aplication registry)
var token = tokenResponse.getToken();

gs.print("$$$ AccessToken:" + token.getAccessToken());
gs.print("$$$ AccessTokenExpiresIn:" + token.getExpiresIn());
gs.print("$$$ RefreshToken:" + token.getRefreshToken());

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@guestee 

3rd party wants to consume ServiceNow endpoint using OAuth?

what's your use-case?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader