fetchUserCode method

Future<String> fetchUserCode()

Implementation

Future<String> fetchUserCode() async {
  final headers = <String, String>{
    'Accept': 'application/json',
    'content-type': 'application/json',
  };

  final body = GitHubJson.encode(<String, dynamic>{
    'client_id': clientId,
    'scope': scopes.join(','),
  });

  final response = await (github == null ? http.Client() : github!.client)
      .post(
        Uri.parse("$baseUrl/login/device/code"),
        body: body,
        headers: headers,
      );

  final json = jsonDecode(response.body) as Map<String, dynamic>;

  _response = json;

  if (json['error'] != null) {
    throw Exception(json['error']);
  }
  return json['user_code'];
}