use of com.xilixir.fortniteapi.v2.Epic.EpicAuthorizationExchange in project FortniteAPI by Xilixir.
the class FortniteAPI method authenticate.
public void authenticate() throws IOException {
log("Starting Authentication...");
Gson gson = new Gson();
// initial login
GenericUrl tokenUrl = new GenericUrl(authTokenEndpoint);
String initialLoginPayload = payloadBuilder(new String[] { "grant_type", "username", "password", "includePerms" }, new String[] { "password", encode(credentials.getEmail()), encode(credentials.getPassword()), "true" });
ByteArrayContent initialLoginContent = new ByteArrayContent("application/x-www-form-urlencoded", initialLoginPayload.getBytes());
HttpRequest initialLoginRequest = factory.buildPostRequest(tokenUrl, initialLoginContent);
initialLoginRequest.getHeaders().setAuthorization("basic " + credentials.getBase64hashPair());
// initial login response
String initialLoginResponse = initialLoginRequest.execute().parseAsString();
this.auth = gson.fromJson(initialLoginResponse, EpicAuthorization.class);
// exchange-1
String authExchangeEndpoint = "https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/exchange";
GenericUrl exchangeUrl = new GenericUrl(authExchangeEndpoint);
HttpRequest exchangeRequest = factory.buildGetRequest(exchangeUrl);
exchangeRequest.getHeaders().setAuthorization("bearer " + this.auth.getAccessToken());
// exchange-1 response
String exchangeResponse = exchangeRequest.execute().parseAsString();
EpicAuthorizationExchange exchange = gson.fromJson(exchangeResponse, EpicAuthorizationExchange.class);
// exchange-2
String exchangeTokenPayload = payloadBuilder(new String[] { "grant_type", "exchange_code", "includePerms", "token_type" }, new String[] { "exchange_code", exchange.getCode(), "true", "eg1" });
ByteArrayContent exchangeTokenContent = new ByteArrayContent("application/x-www-form-urlencoded", exchangeTokenPayload.getBytes());
HttpRequest exchangeTokenRequest = factory.buildPostRequest(tokenUrl, exchangeTokenContent);
exchangeTokenRequest.getHeaders().setAuthorization("basic " + credentials.getBase64hashPairClient());
// exchange-2 response
String exchangeTokenResponse = exchangeTokenRequest.execute().parseAsString();
this.auth = gson.fromJson(exchangeTokenResponse, EpicAuthorization.class);
log("Authenticated successfully!");
this.scheduleTokenRefresh();
}
Aggregations