How to retrieve token utilizing client_credential grant type

daniel chicchon
Mega Contributor

Currently I am utilizing the `password` grant type to retrieve tokens from my instance. However, I would like to try and switch to `clientCredentials` so I don't require user credentials to retrieve tokens. I am using the endpoint `https://instance.service-now.com/oauth_token.do` with the below form.

{
   grant_type: 'client_credentials',
   client_id: 'id',
   client_secret: 'secret'
}

However, when I run this request in Postman, I get a 401 Unauthorized error from my instance. 

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

So, is there something additional I need to configure in order to retrieve tokens? Am I missing something? Any help would be appreciated.

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

Client credential flow works as given below:

  1. The Client Application requests an access token from the Authorization Server by passing it's credentials.
  2. The Authorization Server authenticates the client by validating the client_id and client_secret. Once Validation is successful and if request is valid, it sends an access token.
  3. Client Application sends the received access token to Resource Server to access the resource end point.
  4. Resource Server validates the access token by calling Authorization Server.
  5. If the token is valid, resource server return the requested resource to Client Application.

 

Make sure you are using correct client_id and Client secret. And Grant type is set as 'Client Credential' in ServiceNow Oauth Application. 

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thanks for your response Anil!

So far I have confirmed the client id and secret but am still unable to get a token on my end. Perhaps I may have created an application incorrectly in the Application Registry?