Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

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


* Automatic token retrieving and renewing
* Token expiration control
* Automatic retry on status 401 (UNAUTHORIZED)


Initialize the client and use it as a AsyncHTTPClient object.

.. code-block:: python

from tornadoalf.client import Client

client = Client(

resource_uri = ''

response = yield client.fetch(resource_uri,
method='POST', body='{"name": "alf"}',
headers={'Content-Type': 'application/json'})

How it works?

Before any request the client tries to retrive 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``

After getting the token, the request is issued with a `Bearer authorization
header <>`_:

.. code-block::

GET /resource/1 HTTP/1.1
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.


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 adaptaion to tornado of
`alf <>`_

.. |build-status| image::

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tornado-alf, version 0.4.4
Filename, size File type Python version Upload date Hashes
Filename, size tornado-alf-0.4.4.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page