# Using OAUTH2 authentication in REST requests

**URL:** <https://forum.ansible.com/t/using-oauth2-authentication-in-rest-requests/24386>\
**Category:** Ansible Project\
**Created:** [May 3, 2017, 11:18am UTC](https://forum.ansible.com/t/using-oauth2-authentication-in-rest-requests/24386 "2017-05-03T11:18:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sridhar\_L](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@Sridhar\_L](https://forum.ansible.com/u/Sridhar_L)\
**Post date:** [May 3, 2017, 11:18am UTC](https://forum.ansible.com/t/using-oauth2-authentication-in-rest-requests/24386/1 "2017-05-03T11:18:12Z")

</div>

Hi,

I wanted to use oauth2 based authentication to interact with REST server instead of Basic Auth method. How can I achieve this?

---

<div class="post-metadata">

**Author:** ![Andre\_das\_Neves](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Andre\_das\_Neves](https://forum.ansible.com/u/Andre_das_Neves)\
**Post date:** [January 15, 2021, 4:40am UTC](https://forum.ansible.com/t/using-oauth2-authentication-in-rest-requests/24386/2 "2021-01-15T04:40:17Z")

</div>

It’s been a while… have you succeeded in this task?  
I’m using python requests module and I can run anything using either password or personal tokens. But I’d like to grant access to users using authorization code method. The documentation omits cURL examples for that and it seems that it doesn’t work as other applications do.

As far as I know I should do a POST (to what endpoint I don’t know, I thought it was **/o/authorize/** ) with **client\_id** and receive an **authorization code**. Then I should do a post to **/applications//tokens/** with **client\_id** , **client\_secret** and **authorization code** to get a token. I may be missing something but I shouldn’t have to write my password in the client application, but no matter what I do I keep getting 401 error.

Have someone tried this?
