generateDeviceCodes method

Future<DeviceCodeResponse> generateDeviceCodes({
  1. bool? signup,
})

Generate new codes to start the device authentication process.

The device_code and interval will be used later to poll for the access_token. The user_code and verification_url should be presented to the user as mentioned in the flow steps above.

Implementation

Future<DeviceCodeResponse> generateDeviceCodes({bool? signup}) async {
  final url = Uri.https(_manager._baseURL, "oauth/device/code");
  final response = await _manager.client
      .post(url, headers: {"Content-Type": "application/json"}, body: jsonEncode({"client_id": _manager._clientId}));

  if (![200, 201, 204].contains(response.statusCode)) {
    throw TraktManagerAPIError(response.statusCode, response.reasonPhrase, response);
  }

  final jsonResult = jsonDecode(response.body);
  return DeviceCodeResponse.fromJsonModel(jsonResult);
}