Tutorial to use request_oauth2

I am trying to use the oauth request library for Python to make a request in Pocket. Unfortunately, the description for using this library is not very complete, and I am also new to using oauth2. As a rule, I understand the process behind it, but still I can’t transform it to make the request work.

What I'm looking for is additional documentation or some comprehensive examples of using oauth2 queries. Somebody knows.

In particular, I do not understand what redirect_url to use when a request is only executed using a script on my local computer, but not in a web application.

+6
source share
2 answers

The best source of information I could find is the documentation (and, of course, the source code) of the request-oauth2 project on Github:

The document also contains an Interesting Read section with some links to additional tutorials. For a general overview of the OAuth2 process flow, check out this guide:

Of course, there is also an "old-fashioned" python-oauth2 library that is well documented enough:

The module documentation contains an example of three-way authentication for the Twitter API.

As for the redirect_url field: in general, you can use any URL you want here (even local addresses such as http://localhost/my/endpoint ), the OAuth server just tells HTTP 303 to redirect the request to the client after its authentication which is then processed on the client side. However, some API services (such as Twitter) will require you to specify redict_url in advance and will give up some URLs (e.g. based on IP addresses).

+4
source

If you're a fan of the Python library, I recommend using requests-oauthlib . He has excellent documentation and active developers.

You typically configure redirect_url in your application’s settings on the API Providers website. It seems that Pocket only supports browser-based authentication, so to create an access token, you will need a web browser, which can then be embedded in your script.

+1
source

Source: https://habr.com/ru/post/944874/


All Articles