createOAuthToken method

dynamic createOAuthToken({
  1. required String grantType,
  2. required String grantData,
  3. String tokenType = "eg1",
  4. required String authClient,
})

Authenticate with the Fortnite API

Implementation

dynamic createOAuthToken({
  required String grantType,
  required String grantData,
  String tokenType = "eg1",
  required String authClient,
}) async {
  HttpResponse res = await _client.http.post(
    url: Endpoints().oauthTokenCreate,
    headers: {
      "Authorization": "basic $authClient",
      "Content-Type": "application/x-www-form-urlencoded",
      "User-Agent":
          "Fortnite/++Fortnite+Release-18.21-CL-17811397 Android/11",
    },
    body: "grant_type=$grantType&$grantData&token_type=$tokenType",
  );

  if (res.success) {
    return res.data["access_token"];
  } else {
    if (res.error?["errorCode"] ==
        "errors.com.epicgames.account.invalid_account_credentials") {
      _client.sendInvalidAccountError();
      throw Exception("Your account credentials are invalid");
    }
    throw Exception(res.error?["errorMessage"] ?? "Unknown error");
  }
}