How to secure a Scripted REST API with OAuth using Unified Gateway account in ServiceNow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Team,
I am working on an integration in ServiceNow where an external system needs to send data to a Scripted REST API. We are currently using a Unified Gateway account for the integration.
I would like to understand how we can secure the Scripted REST API using OAuth authentication, especially when the request is coming through the Unified Gateway account.
Specifically, I would like to know:
• How to link OAuth authentication with a Scripted REST API in ServiceNow
• Whether OAuth token validation can be handled through scripting in the Scripted REST API
• What is the recommended approach or best practice for implementing OAuth security when using a Unified Gateway account
If anyone has implemented a similar integration, could you please share the steps or guidance?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ashokakumar
I will recommend to use Client Credentials grant type for secure, token-based machine-to-machine authentication as it removes the need for interactive user login.
• How to link OAuth authentication with a Scripted REST API in ServiceNow
( Ans : Refer: https://www.youtube.com/watch?v=gqqA99rKBJU
https://www.youtube.com/watch?v=xS-8Y6o9hUk
https://www.servicenow.com/community/developer-forum/oauth-for-scripted-rest-api/m-p/2919246)
• Whether OAuth token validation can be handled through scripting in the Scripted REST API (Ans: Refer above links)
• What is the recommended approach or best practice for implementing OAuth security when using a Unified Gateway account ( Ans: Oauth 2.0 is always more secured than basic Auth .Also On the integration account , what kind of permission /role has been given that measures another layer of security there)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ashokakumar ,
You can secure a Scripted REST API with OAuth in ServiceNow using these steps:
Go to System OAuth → Application Registry and create a new OAuth application.
Configure the Client Credentials grant type and share the Client ID and Client Secret with the external system.
The external system generates an access token using the
/oauth_token.doendpoint.While calling the Scripted REST API, the external system sends the token in the Authorization: Bearer header.
Enable Requires authentication on the Scripted REST API so ServiceNow automatically validates the OAuth token.
Assign appropriate roles to the integration (Unified Gateway) user to control API access.
OAuth token validation should not be handled through scripting in the Scripted REST API. ServiceNow automatically validates the token before the API script executes, which is the recommended best practice.
Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.
Regards,
Vaishnavi
Technical Consultant
