getAccessToken method

Future<Map<String, dynamic>?> getAccessToken(
  1. String code
)

Implementation

Future<Map<String, dynamic>?> getAccessToken(String code) async {
  // Map<String, String>?
  try {
    final requestData = {
      'grant_type': 'authorization_code',
      'client_id': clientId,
      'client_secret': clientSecret,
      'code': code,
      'redirect_uri': redirectUrl
    };
    final res = await _dio.post("https://$_domain/oauth/token",
        data: requestData,
        options: Options(headers: {'User-Agent': applicationName}));
    accessToken = res.data["access_token"];
    refreshToken = res.data["refresh_token"];
    return res.data;
  } on DioException catch (e) {
    //print(e.response!.data);
    if (e.response!.statusCode == 404) {
      throw NotFoundException();
    } else {
      throw BadResponseException();
    }
  }
}