Outbound REST web service call using oAuth

dmolnar
Giga Contributor

//authentication type ='basic'/ 'oauth2'

//This line below is optional if you have configured OAuth as authentication type in your outbound REST

r.setAuthentication('oauth2', 'OAuth_Client1');

 

What is OAuth_Client1 referring to?  

I have tried the OAuth Profile name and  oauth_entity name, never worked.

Does anyone know?

1 ACCEPTED SOLUTION

dmolnar
Giga Contributor

This is useful thank everyone. But I was looking for the syntax and how to use it. What I found was the UI Action - "Preview Script". But I did not realize this is no longer used in Geneva+. This was to override the security profile setup in the REST method. The issue is in Geneva (maybe Fuji) and above, this is not used anymore. But I found the answer, was hard to find. Here it is:



Old way:


//override authentication profile


//authentication type ='basic'/ 'oauth2'


//r.setAuthentication(authentication type, profile name);


r.setAuthentication('oauth2', 'OAuth_Client1');



New way:


The new syntax is RESTMessageV2 - setAuthenticationProfile(String type, String profileId)


You can find the details here: RESTMessageV2 - setAuthenticationProfile(String type, String profileId)



NameTypeDescription
typeStringThe type of authentication profile to use. Valid values are 'basic' to use basic authentication, or 'oauth2' to use OAuth 2.0.
profileIdStringThe sys_id of an authentication profile record. When using basic auth, specify the sys_id of a Basic Auth Configuration [sys_auth_profile_basic] record. When using OAuth 2.0, specify the sys_id of a OAuth Entity Profile [oauth_entity_profile] record.

View solution in original post

6 REPLIES 6

dmolnar
Giga Contributor

This is useful thank everyone. But I was looking for the syntax and how to use it. What I found was the UI Action - "Preview Script". But I did not realize this is no longer used in Geneva+. This was to override the security profile setup in the REST method. The issue is in Geneva (maybe Fuji) and above, this is not used anymore. But I found the answer, was hard to find. Here it is:



Old way:


//override authentication profile


//authentication type ='basic'/ 'oauth2'


//r.setAuthentication(authentication type, profile name);


r.setAuthentication('oauth2', 'OAuth_Client1');



New way:


The new syntax is RESTMessageV2 - setAuthenticationProfile(String type, String profileId)


You can find the details here: RESTMessageV2 - setAuthenticationProfile(String type, String profileId)



NameTypeDescription
typeStringThe type of authentication profile to use. Valid values are 'basic' to use basic authentication, or 'oauth2' to use OAuth 2.0.
profileIdStringThe sys_id of an authentication profile record. When using basic auth, specify the sys_id of a Basic Auth Configuration [sys_auth_profile_basic] record. When using OAuth 2.0, specify the sys_id of a OAuth Entity Profile [oauth_entity_profile] record.

shivanipatel
ServiceNow Employee
ServiceNow Employee

Dan,



We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.



If you feel that your question was answered, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This allows other customers to learn from your thread and improves the ServiceNow Community experience.



If you are viewing this from the Community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thanks,


Shivani Patel


Unknown-1.png