Is it possible to use OAuth 2.0 Authentication in SOAP message in Service now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 03:25 AM
Hi Community,
Is it possible to use OAuth 2.0 type authentication in SOAP Message in service now.
As I am not able to find this option in soap authentication method and I am not able to find related documents.
Earlier I configured same in Rest, Is there any other way where we can use OAUTH in SOAP with help of script?
Please let me know your ideas on the same.
Thanks,
Nithin.
- Labels:
-
Platform and Cloud Security
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 06:06 AM
Hi Nithin,
For SOAP OAuth is not supported
Can you mark my answer as correct, helpful Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 08:58 AM
Hi Nithin,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 11:16 PM
Hi Nithin,
You can use Oauth 2.0 for SOAP messages.
Use the SOAPMessageV2() function to trigger the SOAP function and since the TPA was accepting a bearer token in the Request Header was able to pass the OAuth Token via script.
Use the OOB Oauth Token Registry configuration and used the Oauth entity profile to generate the Access token using the GlideOauthClient()
var requestBody;
var response;
var responseBody;
var status;
//var sys_id ='sys_id_of_incident;
try {
var s = new sn_ws.SOAPMessageV2('Incident','get'); //(SOAP messgage name, SOAP function name)
//Generating O Auth access token via script - OAuth Registry definition//
var oAuthClient = new GlideOAuthClient();
var params ={grant_type:"password", username:"test", password:'password123'}; //source instance username and password with user having roles "SOAP" and "ITIL". you can also use client credentials flow
var json =new JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('Target SOAP', text); //Target instance Oauth Entity name
var token = tokenResponse.getToken();
var access_token = token.getAccessToken();
var token = "Bearer "+ access_token.toString();
s.setRequestHeader("Authorization", token); // Using the token information //
//s.setRequestHeader("Content-Type", "text/xml");
//s.setStringParameterNoEscape('sys_id', sys_id);
s.setRequestBody('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inc="http://www.service-now.com/incident"><soapenv:Header/><soapenv:Body><inc:get><sys_id>{enter_incident_sysid_here}</sys_id></inc:get></soapenv:Body></soapenv:Envelope>');
response = s.execute();
responseBody = response.getBody();
status = response.getStatusCode();
requestBody = s.getRequestBody();
var xmldoc = new XMLDocument(responseBody.toString(), true);
var number =xmldoc.getNodeText('//number');
}
catch (ex) {
var message = ex.message;
}
gs.info("Request Body: " + requestBody);
gs.info("Response: " + responseBody);
gs.info("HTTP Status: " + status);
gs.info("Number: " + number);
If my answer has helped with your question, please mark my answer as accepted solution and give a thumbs up.
Best regards,
Tharun Kumar