OAuth 2.0 Client Credentials works in Postman but not from ServiceNow-to-ServiceNow (401 error)

dd31
Tera Contributor
Hi all,
 

I followed all the steps to set up OAuth 2.0 Client Credentials for a ServiceNow-to-ServiceNow integration:

  1. In Instance A (target), created an OAuth Provider (Application Registry) with Client ID, Client Secret, and Redirect URL. Associated a user (with admin role) under OAuth application user.

  2. In Instance B (caller), created an Application Registry to consume Instance A’s credentials (client id, secret, token URL, grant type = Client Credentials).

  3. In Instance B, created a REST Message pointing to Instance A’s Table API, set Authentication type = OAuth 2.0

  4. Clicked on Get OAuth Token — token is generated successfully.

  5. But when I test the HTTP method (GET) in the REST Message, I get:

401 User Not Authenticated - Required to provide Auth information

 

1 ACCEPTED SOLUTION

@dd31, Ok. I achieved that also without using UserID and Password.
Step 1)
All that you need to do is, in your Target Instance from where you got your Client ID and Secret, ensure the "Default Grant type" is set to "Client Credentials" and "OAuth Application User" as your Rest User profile with right level of API access/roles. Like example below.
I gave my Rest User service account "snc_platform_rest_api_access" role. It allows access to Rest APIs:
- Table API
- Import Set API
- Aggregate API
- Attachment API

 

VikMach_0-1757074901800.png



Step 2) In your source instance, from where you're calling the target instance for Token(s), ensure to set "Grant type" in your OAuth Entity Profile as "Client Credentials".
Save the record and go to your REST Message record and click on "Get OAuth Token" related link. It will auto fetch the "Access token" and "Refresh token".

I just tried and it worked for me!

Let me know if any issues.

Regards,
Vikas K

View solution in original post

12 REPLIES 12

@dd31 

The target instance which is the OAuth provider is on Washington?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar Yokohama.

https://www.servicenow.com/community/developer-forum/oauth-for-inbound-rest-request-using-client-cre...

 I have the same concern which is raised in this post, although the post seems to be very old and SN now supports inbound Oauth as per Article: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1645212

@dd31,
Tried and tested your script as well without the UserID and Password. It works like a charm!

VikMach_0-1757076071317.png


Regards,
Vikas K

dd31
Tera Contributor

Not sure what went wrong yesterday. I tried everything even on my PDI, but after deleting and setting it up again today, it somehow worked

It happens sometimes. It's one of those days may be...