Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

OAuth2 token request returned 401

WilliamN2722660
Mega Contributor

I created an Application Registry type "Client Credentials" and am getting this error when I try to connect using the client ID and secret from my application:

401: {"error_description":"access_denied","error":"server_error"}. Check that the Client ID/Secret are still valid and the Application Registry is active.


I configured auth scopes: OAuth APIs, Table APIs, and Attachment APIs

1 REPLY 1

prajaktakha
Tera Expert

Please verify the following:

  1. Enable the Client Credentials grant type

    Check the system property:
    glide.oauth.inbound.client.credential.grant_type.enabled

    Make sure it is set to true and, importantly, create/update this property in the Global scope. A similar issue has been reported where the property was created in a scoped application, which caused authentication to fail.

  2. Configure OAuth Application User

    For the Client Credentials grant, ServiceNow needs an OAuth Application User. Add the OAuth Application User field to the OAuth Entity/Application Registry form through Form Design and select an appropriate active ServiceNow user. ServiceNow states that the authorization request is passed using this associated OAuth Application User.

    Also verify that the selected user has the required roles/ACL access to the APIs you are trying to consume.

  3. Verify the Application Registry

    Make sure:

    • Application Registry is Active

    • Client ID is correct

    • Client Secret is correct and has not been regenerated

    • Grant type is Client Credentials

    • The OAuth Application User is populated

  4. Review the OAuth scopes

    The scopes should match the APIs that the external application needs. However, simply adding OAuth APIs, Table APIs, and Attachment APIs does not by itself guarantee access to the underlying tables. The OAuth scope controls the API access, while the associated OAuth Application User must also have the required permissions/ACLs.

  5. Test the token endpoint directly

    Use:

    POST https://<instance>.service-now.com/oauth_token.do

    with:

    grant_type=client_credentials
    client_id=<client_id>
    client_secret=<client_secret>

    The Client Credentials flow should return an access token, which can then be used as:

    Authorization: Bearer <access_token>

 

If you found this as helpful please accept the solution and mark it as helpful

 

Thanks,

Prajakta