Tornado 的 OAuth 客户端
项目描述
tornado-alf |建造状态|
===========
Tornado OAuth 2 客户端
---------
`tornado-alf` 是基于 tornado 的 OAuth 2 客户端AsyncHTTPClient
功能
--------
* 自动令牌检索和更新
* 令牌过期控制
* 自动重试状态 401 (UNAUTHORIZED)
用法
-----
初始化客户端并将其用作 AsyncHTTPClient 对象。
.. 代码块:: python
from tornadoalf.client import Client
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(resource_uri,
method='POST', body='{"name": "alf"}',
headers={'Content-Type' : 'application/json'})
它是如何工作的?
-------------
在任何请求之前,客户端尝试检索端点上的令牌,
期望带有“access_token”和“expires_in”键的JSON响应。
根据 ``expires_in``
值,客户端保留令牌直到它过期。
获得令牌后,发出请求时带有一个`Bearer authentication
header <http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-7.1>`_:
.. code-block ::
授权:承载令牌
如果请求失败并显示 401(未授权)状态,则会
从端点检索新令牌并重试请求。这只发生一次,如果
再次失败,则返回错误响应。
Troubleshooting
----------------
如果获取令牌出错,将返回错误响应,
不会发生真正的请求。
相关项目
----------------
这个项目试图适应
`alf <https://github.com/globocom/alf>`_
.. |build-的龙卷风状态| 图片::https
://secure.travis-ci.org/globocom/tornado-alf.png?branch=master:目标:https://travis-ci.org/globocom/tornado-alf
===========
Tornado OAuth 2 客户端
---------
`tornado-alf` 是基于 tornado 的 OAuth 2 客户端AsyncHTTPClient
功能
--------
* 自动令牌检索和更新
* 令牌过期控制
* 自动重试状态 401 (UNAUTHORIZED)
用法
-----
初始化客户端并将其用作 AsyncHTTPClient 对象。
.. 代码块:: python
from tornadoalf.client import Client
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(resource_uri,
method='POST', body='{"name": "alf"}',
headers={'Content-Type' : 'application/json'})
它是如何工作的?
-------------
在任何请求之前,客户端尝试检索端点上的令牌,
期望带有“access_token”和“expires_in”键的JSON响应。
根据 ``expires_in``
值,客户端保留令牌直到它过期。
获得令牌后,发出请求时带有一个`Bearer authentication
header <http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-7.1>`_:
.. code-block ::
授权:承载令牌
如果请求失败并显示 401(未授权)状态,则会
从端点检索新令牌并重试请求。这只发生一次,如果
再次失败,则返回错误响应。
Troubleshooting
----------------
如果获取令牌出错,将返回错误响应,
不会发生真正的请求。
相关项目
----------------
这个项目试图适应
`alf <https://github.com/globocom/alf>`_
.. |build-的龙卷风状态| 图片::https
://secure.travis-ci.org/globocom/tornado-alf.png?branch=master:目标:https://travis-ci.org/globocom/tornado-alf