DeviceClient

class oauthlib.oauth2.DeviceClient(client_id, **kwargs)[源代码]

利用设备授权工作流的公共客户端。

客户端可以使用如在RFC8628中定义的设备代码和与该设备代码相关联的公共客户端ID来请求访问令牌。

设备授权授权类型可用于获取访问令牌和刷新令牌,并且旨在用于被授权的设备不具有适合执行身份验证的用户界面的情况。

prepare_request_body(device_code, body='', scope=None, include_client_id=False, **kwargs)[源代码]

将DEVICE_CODE添加到请求正文

客户端通过使用“app/x-www-form-urlencode”格式将DEVICE_CODE作为参数添加到HTTP请求正文,从而向令牌端点发出请求。

参数:
  • body -- 要向其中嵌入参数的现有请求正文(URL编码字符串)。这可能包含额外的参数。默认为‘’。

  • scope -- 访问请求的范围,如 Section 3.3

  • include_client_id (Boolean) -- True 若要发送 client_id in the body of the upstream request. This is required if the client is not authenticating with the authorization server as described in Section 3.2.1 。否则为False(默认)。

  • kwargs -- 要包括在令牌请求中的额外凭据。

准备好的正文将包括所有提供的Device_code以及 grant_type 参数设置为 urn:ietf:params:oauth:grant-type:device_code **

>>> from oauthlib.oauth2 import DeviceClient
>>> client = DeviceClient('your_id', 'your_code')
>>> client.prepare_request_body(scope=['hello', 'world'])
'grant_type=urn:ietf:params:oauth:grant-type:device_code&scope=hello+world'
prepare_request_uri(uri, scope=None, **kwargs)[源代码]

用于创建请求URI的抽象方法。