getRefreshToken method

Future<Map<String, dynamic>> getRefreshToken(
  1. String clientId,
  2. String grantType,
  3. String tokenType,
  4. String refreshToken,
)

Implementation

Future<Map<String, dynamic>> getRefreshToken(String clientId,
    String grantType, String tokenType, String refreshToken) async {
  var body = {
    "client_id": clientId,
    "grant_type": grantType,
    "token_type": tokenType,
    "asymmetric_jwt": "true",
    "refresh_token": refreshToken,
  };
  String formData = body.keys
      .map((key) =>
          "${Uri.encodeComponent(key)}=${Uri.encodeComponent(body[key].toString())}")
      .join("&");

  final response =
      await http.post(Uri.parse('$edxBaseUrl/oauth2/access_token/'),
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
          body: formData);

  var data = json.decode(response.body);

  return data; // Returns the API response
}