OAuth Client For aiohttp
Project description
aio-alf |build-status|
===========
aiohttp OAuth 2 Client
---------------------
`aio-alf` is a OAuth 2 Client base on the aiohttp'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 aioalf.client import Client
from aioalf.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 = await client.request(
'POST',
resource_uri,
data='{"name": "alf"}',
headers={'Content-Type': 'application/json'}
)
Alternatively one can pass directly a string to the fetch client
.. code-block:: python
# ...
response = await client.request(
'POST',
'http://example.com/resource',
data='{"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 aiohttp of
`alf <https://github.com/globocom/alf>`_
.. |build-status| image:: https://secure.travis-ci.org/globocom/aio-alf.png?branch=master
:target: https://travis-ci.org/globocom/aio-alf
===========
aiohttp OAuth 2 Client
---------------------
`aio-alf` is a OAuth 2 Client base on the aiohttp'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 aioalf.client import Client
from aioalf.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 = await client.request(
'POST',
resource_uri,
data='{"name": "alf"}',
headers={'Content-Type': 'application/json'}
)
Alternatively one can pass directly a string to the fetch client
.. code-block:: python
# ...
response = await client.request(
'POST',
'http://example.com/resource',
data='{"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 aiohttp of
`alf <https://github.com/globocom/alf>`_
.. |build-status| image:: https://secure.travis-ci.org/globocom/aio-alf.png?branch=master
:target: https://travis-ci.org/globocom/aio-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
aio-alf-0.1.3.tar.gz
(4.0 kB
view details)
Built Distributions
File details
Details for the file aio-alf-0.1.3.tar.gz
.
File metadata
- Download URL: aio-alf-0.1.3.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79e9cd8ae13d66662e089af5d571eb6157fdeaa101da75787b213073a24246b6 |
|
MD5 | 901f126d2d45d0ed0b268b51403c55fc |
|
BLAKE2b-256 | a4328d42c9f453d1b639a1f964d1f6d3da5341f385a2a51c84e658aa893f9ba4 |
File details
Details for the file aio_alf-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: aio_alf-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 260c3b7ddc840d48622ce998fee7ec1410f706139a9e87a6e7444900f5138a5c |
|
MD5 | b3e8eb60960cf77305ad61898a9b70db |
|
BLAKE2b-256 | 77b8c592f0b519bb2907d2c055deb55e3def5dd82d972137d5f991e79e216df7 |
File details
Details for the file aio_alf-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: aio_alf-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2f15a40fee96e6f4c5e304b314e874b30ea219c2b66ebceaf8730b1ca39d0d |
|
MD5 | 459b407b9f6d5072075bebd401f8d18d |
|
BLAKE2b-256 | a038cf971bca561a3787bc91d51338ba2b49adee0447de8bcd295476df45c03a |