DeviceClient

class oauthlib.oauth2.DeviceClient(client_id, **kwargs)[source]

A public client utilizing the device authorization workflow.

The client can request an access token using a device code and a public client id associated with the device code as defined in RFC8628.

The device authorization grant type can be used to obtain both access tokens and refresh tokens and is intended to be used in a scenario where the device being authorized does not have a user interface that is suitable for performing authentication.

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

Add device_code to request body

The client makes a request to the token endpoint by adding the device_code as a parameter using the “application/x-www-form-urlencoded” format to the HTTP request body.

Parameters:
  • body – Existing request body (URL encoded string) to embed parameters into. This may contain extra parameters. Default ‘’.
  • scope – The scope of the access request as described by Section 3.3.
  • include_client_id (Boolean) – True to send the 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 otherwise (default).
  • kwargs – Extra credentials to include in the token request.

The prepared body will include all provided device_code as well as the grant_type parameter set to 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)[source]

Abstract method used to create request URIs.