Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tutorial for using requests_oauth2

I am trying to use the requests-oauth library for Python to make a request to Pocket. Unfortunately the description to use this library is not very comprehensive and I am also new to use oauth2. Generally I understand the process behind it but still can not convert this to get the request to work.

What I am looking for is abetter documentation or some comprehensive examples to use requests-oauth2. Does anyone know.

Especially I am not understanding what redirect_url to use when the request is made only by a script on my local machine but not a web application.

like image 692
Cutú Chiqueño Avatar asked May 13 '13 11:05

Cutú Chiqueño


2 Answers

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

  • https://github.com/maraujop/requests-oauth2

The document also contains an "Interesting readings" section with some links to additional tutorials. For a general overview of the OAuth2 process flow, have a look at this tutorial:

  • http://apiwiki.poken.com/authentication/oauth2

Of course there is also the "old-fashioned" python-oauth2 library, which is quite well-documented:

  • https://github.com/simplegeo/python-oauth2

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

Concerning 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 will simply issue a HTTP 303 redirect request to the client after authenticating him, which is then processed on the client-side. However, some API services (such as Twitter) will require you to specify the redict_url beforehand and will refuse some URLs (e.g. IP-based ones).

like image 69
ThePhysicist Avatar answered Sep 23 '22 00:09

ThePhysicist


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

Normally you setup the redirect_url in your application's settings on the API providers website. It looks like Pocket only supports browser based authentication, so you'll need a web browser to generate an access token that you can then embed in your script.

like image 32
devin_s Avatar answered Sep 20 '22 00:09

devin_s