oauthTokenRequest method

Future<OAuthTokenResponse> oauthTokenRequest(
  1. String provider,
  2. OAuthTokenRequest params
)

Implementation

Future<OAuthTokenResponse> oauthTokenRequest(String provider, OAuthTokenRequest params) async {
  final url = Uri.parse('${_wepinBaseUrl}user/oauth/token/$provider');
  final jsonRequestBody = jsonEncode(params.toJson());
  final response = await http.post(
    url,
    headers: headers,
    body: jsonRequestBody,
  );

  if (response.statusCode >= 200 && response.statusCode < 300) {
    final responseBody = jsonDecode(response.body);
    return OAuthTokenResponse.fromJson(responseBody);
  } else {
    throw WepinError(WepinErrorCode.apiRequestError, 'code: ${response.statusCode} , body: ${response.body}');
  }
}