请求令牌

class oauthlib.oauth1.RequestTokenEndpoint(request_validator, token_generator=None)[源代码]

负责提供OAuth 1请求令牌的端点。

典型用法是使用请求验证器实例化并调用 create_request_token_response 从VIEW函数。返回的元组包含快速形成和返回正确响应所需的所有信息(正文、状态、标头)。看见 请求验证器 有关为此终结点实现哪些验证器方法的详细信息。

create_request_token(request, credentials)[源代码]

创建并保存新的请求令牌。

参数:
  • request (oauthlib.common.Request) -- OAuthlib请求。

  • credentials -- 额外令牌凭据的字典。

返回:

URL编码字符串形式的令牌。

create_request_token_response(uri, http_method='GET', body=None, headers=None, credentials=None)[源代码]

创建请求令牌响应,如果有效,则使用新的请求令牌。

参数:
  • uri -- 令牌请求的完整URI。

  • http_method -- 有效的HTTP谓词,即GET、POST、PUT、HEAD等。

  • body -- 字符串形式的请求正文。

  • headers -- 请求标头作为字典。

  • credentials -- 要包括在令牌中的额外凭据列表。

返回:

由3个元素组成的元组。1.要在响应上设置的标头字典。2.字符串形式的响应Body。3.响应状态码,整型。

有效请求的示例::

>>> from your_validator import your_validator
>>> from oauthlib.oauth1 import RequestTokenEndpoint
>>> endpoint = RequestTokenEndpoint(your_validator)
>>> h, b, s = endpoint.create_request_token_response(
...     'https://your.provider/request_token?foo=bar',
...     headers={
...         'Authorization': 'OAuth realm=movies user, oauth_....'
...     },
...     credentials={
...         'my_specific': 'argument',
...     })
>>> h
{'Content-Type': 'application/x-www-form-urlencoded'}
>>> b
'oauth_token=lsdkfol23w54jlksdef&oauth_token_secret=qwe089234lkjsdf&oauth_callback_confirmed=true&my_specific=argument'
>>> s
200

对无效请求的响应将具有不同的正文和状态::

>>> b
'error=invalid_request&description=missing+callback+uri'
>>> s
400

未经授权的请求也是如此:

>>> b
''
>>> s
401
validate_request_token_request(request)[源代码]

验证请求令牌请求。

参数:

request (oauthlib.common.Request) -- OAuthlib请求。

加薪:

如果请求无效,则返回OAuth1Error。

返回:

由2个元素组成的元组。1.验证结果(True或False)。2.请求对象。