OAuth Access Token Request

tjrigario
Kilo Contributor

Hello,

I believe that there is an error either in the product documentation or the OAuth implementation. Upon requesting an access token with valid credentials, I consistently receive a 401 Unauthorized message.

JSON Response: {"error":"server_error","error_description":"access_denied"}

I've been unsuccessful at making the OAuth implementation work at all. Using the classic Authorization header method works just fine.

Chris

1 ACCEPTED SOLUTION

mayank3103
Giga Contributor

Replying to this post a bit late, so joining the party when this might be resolved. But might be helpful for others



I was also having a similar issue.


JSON Response: {"error":"server_error","error_description":"access_denied"}



Steps taken:


1) Make sure Authorization is "No Auth"


find_real_file.png


2) Make sure the Body is x-www-form-encoded


curl -X POST \


  https:///instance.service-now.com/oauth_token.do \


  -H 'cache-control: no-cache' \


  -H 'content-type: application/x-www-form-urlencoded' \


  -H 'postman-token: 53f8a8f7-f286-607f-1e7e-8dab629081fb' \


  -d 'grant_type=password&client_id=ac0dd3408c1031006907010c2cc6ef6d&client_secret=bv4gg7o7akbc18jjy13m&username=admin&password=admin'


find_real_file.png


3) As a result you would see the Request Headers automatically pulled up as


find_real_file.png



Now use the access_token in subsequent requests. Adding the header as Authorization: Bearer <access_token>


curl -X GET \


  'https:///instance.service-now.com/api/now/table/sys_user?sysparm_display_value=true&sysparm_fields=n...' \


  -H 'authorization: Bearer Icru5EyU4ZrgngoB0ecHp_LcXJHm-nB1NBt2QXaEXhYoPZcd6ss6KS4mLGfApGDDsi6ka86zdabHMgKX8doeHA' \


  -H 'cache-control: no-cache' \


  -H 'postman-token: e2073e4f-d09e-f19b-b510-5779f9ba415a' \


find_real_file.png


View solution in original post

23 REPLIES 23

allwyn1
Kilo Explorer

Thanks Venkat for the reply: I do have the Advance chrome extension as well. As soon as I put in this url I get the same error message again.     When I tried using plsql also I got same error message.   Let me know if you want to do an webex session or send me your contact I will reach out to you.



Allwyn




venkata_koya
ServiceNow Employee
ServiceNow Employee

Looking at snapshot, you are making request to oauth endpoint in browser window. It makes a http GET request to endpoint. You are supposed to do POST request to oauth endpoint.


You need to open advanced rest client chrome extension and fill out details as shown in my screen shot.


allwyn1
Kilo Explorer

Sorry I did open Advance rest api and did an POST as mentioned as access denied   error message




venkata_koya
ServiceNow Employee
ServiceNow Employee

Funny, you did same mistake as i did.


You added the parameters as headers not as post body.


allwyn1
Kilo Explorer

Sorry What do I need to do to resolve this?   Thanks again for your prompt reply



Allwyn