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.

How to use OAuth Bearer Token in Outbound Soap Web Service?

Artemis15
Kilo Guru

Hi,

 

We need to call a SOAP web-service in servicenow by which we need to post some data. That SOAP web-service is using OAuth authentication. We need to pass Authentication type as Bearer. But we are not able to do that.

 

Thanks,

Akash Rajput

2 REPLIES 2

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Realize you are using SOAP, but this article on REST should help:


Using OAUTH Tokens with REST Interfaces



Basically you need to pass in a new header:


Web Service Consumer Support - ServiceNow Wiki


andrewrump
Mega Contributor

Have anyone managed to get an oAuth token they can use to manually talk to a SOAP service?


I was hoping ServiceNow SOAP implementation supported oAuth as it does with REST but that is not the case.



I have problems getting an access token using https://api.cisco.com/pss/token - it complains that the client is invalid.



I can get it to work using curl:


curl -d "grant_type=client_credentials&client_id=7fvv&client_secret=NaQc" https://api.cisco.com/pss/token



But when I try to do the same thing inside ServiceNow with the following code:


var sm = new sn_ws.RESTMessageV2();



sm.setEndpoint('https://api.cisco.com/pss/token');


sm.setHttpMethod('post');


sm.setQueryParameter('grant_type', 'client_credentials');


sm.setQueryParameter('client_id', '7fvv');


sm.setQueryParameter('client_secret', 'NaQc');



var response = sm.execute();



I get the following responses:


  1. response.getStatusCode() returns: 401
  2. response.getErrorMessage() returns: Method failed: (/pss/token/) with code: 401 - Invalid username/password combo
  3. response.getBody() returns: {"error":"invalid_client"}


I tried to add sm.setRequestHeader('Accept', 'application/json'); before performing the execute() but that also did not make any difference.



I've tried using GlideHTTPRequest() and get the same result