OAuth Client For Tornado
Project description
tornado-alf |build-status|
===========
Tornado OAuth 2 Client
---------------------
`tornado-alf` is a OAuth 2 Client base on the tornado's AsyncHTTPClient
Features
--------
* Automatic token retrieving and renewing
* Token expiration control
* Automatic retry on status 401 (UNAUTHORIZED)
Usage
-----
Initialize the client and use it as a AsyncHTTPClient object.
.. code-block:: python
from tornadoalf.client import Client
from tornadoalf.httpclient import HTTPRequest
client = Client(
token_endpoint='http://example.com/token',
client_id='client-id',
client_secret='secret')
resource_uri = 'http://example.com/resource'
response = yield client.fetch(HTTPRequest(resource_uri),
method='POST', body='{"name": "alf"}',
headers={'Content-Type': 'application/json'})
Alternatively one can pass directly a string to the fetch client
.. code-block:: python
# ...
response = yield client.fetch('http://example.com/resource',
method='POST', body='{"name": "alf"}',
headers={'Content-Type': 'application/json'})
How it works?
-------------
Before any request the client tries to retrieve a token on the endpoint,
expecting a JSON response with the ``access_token`` and ``expires_in`` keys.
The client keeps the token until it is expired, according to the ``expires_in``
value.
After getting the token, the request is issued with a `Bearer authorization
header <http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-7.1>`_:
.. code-block::
GET /resource/1 HTTP/1.1
Host: example.com
Authorization: Bearer token
If the request fails with a 401 (UNAUTHORIZED) status, a new token is retrieved
from the endpoint and the request is retried. This happens only once, if it
fails again the error response is returned.
Troubleshooting
---------------
In case of an error retrieving a token, the error response will be returned,
the real request won't happen.
Related projects
----------------
This project tries to be an adaptation to tornado of
`alf <https://github.com/globocom/alf>`_
.. |build-status| image:: https://secure.travis-ci.org/globocom/tornado-alf.png?branch=master
:target: https://travis-ci.org/globocom/tornado-alf
===========
Tornado OAuth 2 Client
---------------------
`tornado-alf` is a OAuth 2 Client base on the tornado's AsyncHTTPClient
Features
--------
* Automatic token retrieving and renewing
* Token expiration control
* Automatic retry on status 401 (UNAUTHORIZED)
Usage
-----
Initialize the client and use it as a AsyncHTTPClient object.
.. code-block:: python
from tornadoalf.client import Client
from tornadoalf.httpclient import HTTPRequest
client = Client(
token_endpoint='http://example.com/token',
client_id='client-id',
client_secret='secret')
resource_uri = 'http://example.com/resource'
response = yield client.fetch(HTTPRequest(resource_uri),
method='POST', body='{"name": "alf"}',
headers={'Content-Type': 'application/json'})
Alternatively one can pass directly a string to the fetch client
.. code-block:: python
# ...
response = yield client.fetch('http://example.com/resource',
method='POST', body='{"name": "alf"}',
headers={'Content-Type': 'application/json'})
How it works?
-------------
Before any request the client tries to retrieve a token on the endpoint,
expecting a JSON response with the ``access_token`` and ``expires_in`` keys.
The client keeps the token until it is expired, according to the ``expires_in``
value.
After getting the token, the request is issued with a `Bearer authorization
header <http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-7.1>`_:
.. code-block::
GET /resource/1 HTTP/1.1
Host: example.com
Authorization: Bearer token
If the request fails with a 401 (UNAUTHORIZED) status, a new token is retrieved
from the endpoint and the request is retried. This happens only once, if it
fails again the error response is returned.
Troubleshooting
---------------
In case of an error retrieving a token, the error response will be returned,
the real request won't happen.
Related projects
----------------
This project tries to be an adaptation to tornado of
`alf <https://github.com/globocom/alf>`_
.. |build-status| image:: https://secure.travis-ci.org/globocom/tornado-alf.png?branch=master
:target: https://travis-ci.org/globocom/tornado-alf
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tornado-alf-0.5.0rc1.tar.gz
(4.5 kB
view details)
File details
Details for the file tornado-alf-0.5.0rc1.tar.gz
.
File metadata
- Download URL: tornado-alf-0.5.0rc1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf6a0fe74336a4f698e94386eeece3ed98c26f15d1510a3bd09a24ddec743a57 |
|
MD5 | 3d20045b7c531191d08a4724190ec5bc |
|
BLAKE2b-256 | 0f001a01ac68fe72ee0f809a3bf58d86c53f4e02e35a57529ff06f248e9137ee |