login method

Future<Map<String, dynamic>?> login(
  1. String username,
  2. String password,
  3. String clientId,
  4. String grant_type,
  5. String tokenType,
  6. String asymmetricJwt,
)

Implementation

Future<Map<String, dynamic>?> login(
    String username,
    String password,
    String clientId,
    String grant_type,
    String tokenType,
    String asymmetricJwt) async {
  final body = {
    'username': username,
    'password': password,
    'grant_type': grant_type,
    "client_id": clientId,
    "token_type": tokenType,
    "asymmetric_jwt": asymmetricJwt
  };
  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; // Return null if redirectUri is not in the response or token is not found
}