BackendApplicationClient

class oauthlib.oauth2.BackendApplicationClient(client_id, default_token_placement='auth_header', token_type='Bearer', access_token=None, refresh_token=None, mac_key=None, mac_algorithm=None, token=None, scope=None, state=None, redirect_url=None, state_generator=<function generate_token>, code_verifier=None, code_challenge=None, code_challenge_method=None, **kwargs)[源代码]

使用客户端凭据的公共客户端授予工作流。

当客户端请求访问其控制下的受保护资源时,客户端可以仅使用其客户端证书(或其他受支持的认证手段)来请求访问令牌,或者使用先前与授权服务器安排的另一资源所有者的客户端证书(其方法超出本说明书的范围)来请求访问令牌。

客户端凭据授予类型只能由机密客户端使用。

由于使用客户端身份验证作为授权授权,因此不需要额外的授权请求。

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

将客户端凭据添加到请求正文。

客户端通过添加以下参数向令牌端点发出请求,该参数的格式为 Appendix B 在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 -- 要包括在令牌请求中的额外凭据。

客户端必须通过授权服务器进行身份验证,如中所述 Section 3.2.1

准备好的正文将包括所有提供的凭据以及 grant_type 参数设置为 client_credentials **

>>> from oauthlib.oauth2 import BackendApplicationClient
>>> client = BackendApplicationClient('your_id')
>>> client.prepare_request_body(scope=['hello', 'world'])
'grant_type=client_credentials&scope=hello+world'