# Cannot access AWX API using OAuth 2 token

**URL:** <https://forum.ansible.com/t/cannot-access-awx-api-using-oauth-2-token/3708>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [February 6, 2024, 4:22pm UTC](https://forum.ansible.com/t/cannot-access-awx-api-using-oauth-2-token/3708 "2024-02-06T16:22:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [February 6, 2024, 4:22pm UTC](https://forum.ansible.com/t/cannot-access-awx-api-using-oauth-2-token/3708/1 "2024-02-06T16:22:29Z")

</div>

With AWX 23.5.2, I can authenticate and access the API using a browser without any issue.

However, trying to automate it with the CLI in a different matter…

Getting an OAuth 2 token:

```auto
curl -u awx_user:password -k -X POST https://awx_host/api/v2/tokens/
{
  "id": 22,
  "type": "o_auth2_access_token",
  "url": "/api/v2/tokens/22/",
  "related": {
    "user": "/api/v2/users/1/",
    "activity_stream": "/api/v2/tokens/22/activity_stream/"
  },
  "summary_fields": {
    "user": {
      "id": 1,
      "username": "awx_user",
      "first_name": "",
      "last_name": ""
    }
  },
  "created": "2024-02-06T16:03:56.006883Z",
  "modified": "2024-02-06T16:03:56.018615Z",
  "description": "",
  "user": 1,
  "token": "TlTzso87sycucOXpmsA3tTVlsNwtGj",
  "refresh_token": null,
  "application": null,
  "expires": "3023-06-09T16:03:55.994224Z",
  "scope": "write"
}

```

As described in the [official doc](https://ansible.readthedocs.io/projects/awx/en/latest/rest_api/authentication.html#id3), I tried to use this token to access any object, but this fails:

```auto
curl -k -X GET -H “Content-Type: application/json” -H “Authorization: Bearer TlTzso87sycucOXpmsA3tTVlsNwtGj” https://awx_host/api/v2/credentials/
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>
{"detail":"Authentication credentials were not provided. To establish a login session, visit /api/login/."}++ set +x

```

What is going on?  
What is the correct way to use this token?

---

<div class="post-metadata">

**Author:** ![fosterseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/fosterseth/32/101_2.png) [@fosterseth](https://forum.ansible.com/u/fosterseth)\
**Post date:** [February 7, 2024, 7:59pm UTC](https://forum.ansible.com/t/cannot-access-awx-api-using-oauth-2-token/3708/2 "2024-02-07T19:59:05Z")

</div>

I used your exact curl commands and it worked locally for me, so you are using them correctly.

I’ll mention that the doc curl command under Basic Auth has an example with “Authorization: Basic …”, that is incorrect

tokens should use Authorization: Bearer

Seth

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [February 14, 2024, 3:17pm UTC](https://forum.ansible.com/t/cannot-access-awx-api-using-oauth-2-token/3708/3 "2024-02-14T15:17:20Z")

</div>

Then you must be using a different AWX version.

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [February 26, 2024, 5:34pm UTC](https://forum.ansible.com/t/cannot-access-awx-api-using-oauth-2-token/3708/4 "2024-02-26T17:34:05Z")

</div>

Anyway, I’m using the token module now and it works flawlessly so far.
