Getting 401 Unauthorized Error while trying to get OAuth token from ServiceNow to authenticate against Ansible Automation Platform

Solution Verified - Updated -

Environment

  • Ansible Automation Platform 2.4 and 2.5
  • ServiceNow

Issue

  • While trying to connect ServiceNow as an application in the Ansible Automation Platform, each time when clicking the Get Oauth Token button on the ServiceNow REST Message screen.

  • To fetch the OAuth Token to authenticate against the controller server. We get the below error:

    HTTP Error 401 - Unauthorized
    

Resolution

  • This is not an issue of Ansible Automation Platform, however, ServiceNow is returning 401 Unauthorized error as it is unable to parse the AUTH code.

Root Cause

  • The ServiceNow - Ansible Automation Platform workflow is described below:

    • When we click on the Get Oauth Token -> Authorize ServiceNow, It sends an API request to the controller/gateway:
      AAP 2.4 and older: https://conroller_url/api/o/authorize/
      AAP 2.5: https://gateway_url/o/authorize/
      The controller/gateway responds back with the Auth code, which can be seen in the url on SNow.

    • After which ServiceNow has to parse that auth code and send a POST request at:
      AAP 2.4 and older: https://conroller_url/api/o/token/
      AAP 2.5: https://gateway_url/o/token/
      to get the token using the AUTH code. The controller/gateway receives the request & sends back the Token.

    • ServiceNow can then use this token for any API requests to the controller/gateway.

    • But the issue here is, ServiceNow is returning 401 Unauthorized Error as it is unable to parse the AUTH code.

Diagnostic Steps

  • The workflow requests and responds can be verified by checking the nginx access.log while performing the above steps.
  • # tail -f /var/log/nginx/access.log

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments