Skip to content

Commit

Permalink
Renamed some local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Nov 13, 2023
1 parent cdf29a0 commit ac5167c
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 225 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/raphimc/minecraftauth/MinecraftAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static class MsaTokenBuilder {
private String clientId = MicrosoftConstants.JAVA_TITLE_ID;
private String scope = MicrosoftConstants.SCOPE1;
private String clientSecret = null;
private int timeout = 60;
private int timeout = 120;
private String redirectUri = null;

private AbstractStep<?, MsaCodeStep.MsaCode> msaCodeStep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public StepMCChain(final AbstractStep<?, StepXblXstsToken.XblXsts<?>> prevStep)
}

@Override
public MCChain applyStep(final HttpClient httpClient, final StepXblXstsToken.XblXsts<?> prevResult) throws Exception {
public MCChain applyStep(final HttpClient httpClient, final StepXblXstsToken.XblXsts<?> xblXsts) throws Exception {
MinecraftAuth.LOGGER.info("Authenticating with Minecraft Services...");

final KeyPairGenerator secp384r1 = KeyPairGenerator.getInstance("EC");
Expand All @@ -71,7 +71,7 @@ public MCChain applyStep(final HttpClient httpClient, final StepXblXstsToken.Xbl

final HttpPost httpPost = new HttpPost(MINECRAFT_LOGIN_URL);
httpPost.setEntity(new StringEntity(postData.toString(), ContentType.APPLICATION_JSON));
httpPost.addHeader("Authorization", "XBL3.0 x=" + prevResult.getUserHash() + ";" + prevResult.getToken());
httpPost.addHeader("Authorization", "XBL3.0 x=" + xblXsts.getUserHash() + ";" + xblXsts.getToken());
final String response = httpClient.execute(httpPost, new BasicResponseHandler());
final JsonObject obj = JsonParser.parseString(response).getAsJsonObject();
final JsonArray chain = obj.get("chain").getAsJsonArray();
Expand All @@ -90,25 +90,25 @@ public MCChain applyStep(final HttpClient httpClient, final StepXblXstsToken.Xbl
MinecraftAuth.LOGGER.warn("Minecraft chain does not contain titleId! You might get kicked from some servers");
}

final MCChain result = new MCChain(
final MCChain mcChain = new MCChain(
publicKey,
privateKey,
chain.get(0).getAsString(),
chain.get(1).getAsString(),
xuid,
id,
displayName,
prevResult
xblXsts
);
MinecraftAuth.LOGGER.info("Got MC Chain, name: " + result.displayName + ", uuid: " + result.id + ", xuid: " + result.xuid);
return result;
MinecraftAuth.LOGGER.info("Got MC Chain, name: " + mcChain.displayName + ", uuid: " + mcChain.id + ", xuid: " + mcChain.xuid);
return mcChain;
}

@Override
public MCChain refresh(final HttpClient httpClient, final MCChain result) throws Exception {
if (result.isExpired()) return super.refresh(httpClient, result);
public MCChain refresh(final HttpClient httpClient, final MCChain mcChain) throws Exception {
if (mcChain.isExpired()) return super.refresh(httpClient, mcChain);

return result;
return mcChain;
}

@Override
Expand All @@ -127,16 +127,16 @@ public MCChain fromJson(final JsonObject json) {
}

@Override
public JsonObject toJson(final MCChain result) {
public JsonObject toJson(final MCChain mcChain) {
final JsonObject json = new JsonObject();
json.addProperty("publicKey", Base64.getEncoder().encodeToString(result.publicKey.getEncoded()));
json.addProperty("privateKey", Base64.getEncoder().encodeToString(result.privateKey.getEncoded()));
json.addProperty("mojangJwt", result.mojangJwt);
json.addProperty("identityJwt", result.identityJwt);
json.addProperty("xuid", result.xuid);
json.addProperty("id", result.id.toString());
json.addProperty("displayName", result.displayName);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.xblXsts));
json.addProperty("publicKey", Base64.getEncoder().encodeToString(mcChain.publicKey.getEncoded()));
json.addProperty("privateKey", Base64.getEncoder().encodeToString(mcChain.privateKey.getEncoded()));
json.addProperty("mojangJwt", mcChain.mojangJwt);
json.addProperty("identityJwt", mcChain.identityJwt);
json.addProperty("xuid", mcChain.xuid);
json.addProperty("id", mcChain.id.toString());
json.addProperty("displayName", mcChain.displayName);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(mcChain.xblXsts));
return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public StepPlayFabToken(final AbstractStep<?, StepXblXstsToken.XblXsts<?>> prevS
}

@Override
public PlayFabToken applyStep(final HttpClient httpClient, final StepXblXstsToken.XblXsts<?> prevResult) throws Exception {
public PlayFabToken applyStep(final HttpClient httpClient, final StepXblXstsToken.XblXsts<?> xblXsts) throws Exception {
MinecraftAuth.LOGGER.info("Authenticating with PlayFab...");

final JsonObject postData = new JsonObject();
Expand All @@ -68,7 +68,7 @@ public PlayFabToken applyStep(final HttpClient httpClient, final StepXblXstsToke
postData.add("InfoRequestParameters", infoRequestParameters);
postData.add("PlayerSecret", null);
postData.addProperty("TitleId", MicrosoftConstants.BEDROCK_PLAY_FAB_TITLE_ID);
postData.addProperty("XboxToken", "XBL3.0 x=" + prevResult.getUserHash() + ";" + prevResult.getToken());
postData.addProperty("XboxToken", "XBL3.0 x=" + xblXsts.getUserHash() + ";" + xblXsts.getToken());

final HttpPost httpPost = new HttpPost(PLAY_FAB_URL);
httpPost.setEntity(new StringEntity(postData.toString(), ContentType.APPLICATION_JSON));
Expand All @@ -77,23 +77,23 @@ public PlayFabToken applyStep(final HttpClient httpClient, final StepXblXstsToke
final JsonObject data = obj.getAsJsonObject("data");
final JsonObject entityToken = data.getAsJsonObject("EntityToken");

final PlayFabToken result = new PlayFabToken(
final PlayFabToken playFabToken = new PlayFabToken(
Instant.parse(entityToken.get("TokenExpiration").getAsString()).toEpochMilli(),
entityToken.get("EntityToken").getAsString(),
entityToken.get("Entity").getAsJsonObject().get("Id").getAsString(),
data.get("SessionTicket").getAsString(),
data.get("PlayFabId").getAsString(),
prevResult
xblXsts
);
MinecraftAuth.LOGGER.info("Got PlayFab Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault()));
return result;
MinecraftAuth.LOGGER.info("Got PlayFab Token, expires: " + Instant.ofEpochMilli(playFabToken.getExpireTimeMs()).atZone(ZoneId.systemDefault()));
return playFabToken;
}

@Override
public PlayFabToken refresh(final HttpClient httpClient, final PlayFabToken result) throws Exception {
if (result.isExpired()) return super.refresh(httpClient, result);
public PlayFabToken refresh(final HttpClient httpClient, final PlayFabToken playFabToken) throws Exception {
if (playFabToken.isExpired()) return super.refresh(httpClient, playFabToken);

return result;
return playFabToken;
}

@Override
Expand All @@ -110,14 +110,14 @@ public PlayFabToken fromJson(final JsonObject json) {
}

@Override
public JsonObject toJson(final PlayFabToken result) {
public JsonObject toJson(final PlayFabToken playFabToken) {
final JsonObject json = new JsonObject();
json.addProperty("expireTimeMs", result.expireTimeMs);
json.addProperty("entityToken", result.entityToken);
json.addProperty("entityId", result.entityId);
json.addProperty("sessionTicket", result.sessionTicket);
json.addProperty("playFabId", result.playFabId);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.xblXsts));
json.addProperty("expireTimeMs", playFabToken.expireTimeMs);
json.addProperty("entityToken", playFabToken.entityToken);
json.addProperty("entityId", playFabToken.entityId);
json.addProperty("sessionTicket", playFabToken.sessionTicket);
json.addProperty("playFabId", playFabToken.playFabId);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(playFabToken.xblXsts));
return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ protected FullBedrockSession fromDeduplicatedJson(final JsonObject json) {
}

@Override
protected JsonObject toRawJson(final FullBedrockSession result) {
protected JsonObject toRawJson(final FullBedrockSession fullBedrockSession) {
final JsonObject json = new JsonObject();
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.mcChain));
if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(result.playFabToken));
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(fullBedrockSession.mcChain));
if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(fullBedrockSession.playFabToken));
return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public MCProfile applyStep(final HttpClient httpClient, final StepMCToken.MCToke
throw new IOException("No valid minecraft profile found: " + obj);
}

final MCProfile result = new MCProfile(
final MCProfile mcProfile = new MCProfile(
UUID.fromString(obj.get("id").getAsString().replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5")),
obj.get("name").getAsString(),
obj.get("skins").getAsJsonArray().get(0).getAsJsonObject().get("url").getAsString(),
mcToken
);
MinecraftAuth.LOGGER.info("Got MC Profile, name: " + result.name + ", uuid: " + result.id);
return result;
MinecraftAuth.LOGGER.info("Got MC Profile, name: " + mcProfile.name + ", uuid: " + mcProfile.id);
return mcProfile;
}

@Override
Expand All @@ -73,12 +73,12 @@ public MCProfile fromJson(final JsonObject json) {
}

@Override
public JsonObject toJson(final MCProfile result) {
public JsonObject toJson(final MCProfile mcProfile) {
final JsonObject json = new JsonObject();
json.addProperty("id", result.id.toString());
json.addProperty("name", result.name);
json.addProperty("skinUrl", result.skinUrl);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.mcToken));
json.addProperty("id", mcProfile.id.toString());
json.addProperty("name", mcProfile.name);
json.addProperty("skinUrl", mcProfile.skinUrl);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(mcProfile.mcToken));
return json;
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/java/net/raphimc/minecraftauth/step/java/StepMCToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ public MCToken applyStep(final HttpClient httpClient, final StepXblXstsToken.Xbl
final String response = httpClient.execute(httpPost, new BasicResponseHandler());
final JsonObject obj = JsonParser.parseString(response).getAsJsonObject();

final MCToken result = new MCToken(
final MCToken mcToken = new MCToken(
obj.get("access_token").getAsString(),
obj.get("token_type").getAsString(),
System.currentTimeMillis() + obj.get("expires_in").getAsLong() * 1000,
xblXsts
);
MinecraftAuth.LOGGER.info("Got MC Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault()));
return result;
MinecraftAuth.LOGGER.info("Got MC Token, expires: " + Instant.ofEpochMilli(mcToken.getExpireTimeMs()).atZone(ZoneId.systemDefault()));
return mcToken;
}

@Override
public MCToken refresh(final HttpClient httpClient, final MCToken result) throws Exception {
if (result.isExpired()) return super.refresh(httpClient, result);
public MCToken refresh(final HttpClient httpClient, final MCToken mcToken) throws Exception {
if (mcToken.isExpired()) return super.refresh(httpClient, mcToken);

return result;
return mcToken;
}

@Override
Expand All @@ -82,12 +82,12 @@ public MCToken fromJson(final JsonObject json) {
}

@Override
public JsonObject toJson(final MCToken result) {
public JsonObject toJson(final MCToken mcToken) {
final JsonObject json = new JsonObject();
json.addProperty("accessToken", result.accessToken);
json.addProperty("tokenType", result.tokenType);
json.addProperty("expireTimeMs", result.expireTimeMs);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.xblXsts));
json.addProperty("accessToken", mcToken.accessToken);
json.addProperty("tokenType", mcToken.tokenType);
json.addProperty("expireTimeMs", mcToken.expireTimeMs);
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(mcToken.xblXsts));
return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ public PlayerCertificates applyStep(final HttpClient httpClient, final StepMCTok
);
final RSAPublicKey publicKey = (RSAPublicKey) CryptUtil.RSA_KEYFACTORY.generatePublic(encodedPublicKey);

final PlayerCertificates result = new PlayerCertificates(
final PlayerCertificates playerCertificates = new PlayerCertificates(
Instant.parse(obj.get("expiresAt").getAsString()).toEpochMilli(),
publicKey,
privateKey,
Base64.getMimeDecoder().decode(obj.get("publicKeySignatureV2").getAsString()),
obj.has("publicKeySignature") ? Base64.getMimeDecoder().decode(obj.get("publicKeySignature").getAsString()) : new byte[0],
mcToken
);
MinecraftAuth.LOGGER.info("Got player certificates, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault()));
return result;
MinecraftAuth.LOGGER.info("Got player certificates, expires: " + Instant.ofEpochMilli(playerCertificates.getExpireTimeMs()).atZone(ZoneId.systemDefault()));
return playerCertificates;
}

@Override
public PlayerCertificates refresh(final HttpClient httpClient, final PlayerCertificates result) throws Exception {
if (result.isExpired()) return super.refresh(httpClient, result);
public PlayerCertificates refresh(final HttpClient httpClient, final PlayerCertificates playerCertificates) throws Exception {
if (playerCertificates.isExpired()) return super.refresh(httpClient, playerCertificates);

return result;
return playerCertificates;
}

@Override
Expand All @@ -102,14 +102,14 @@ public PlayerCertificates fromJson(final JsonObject json) {
}

@Override
public JsonObject toJson(final PlayerCertificates result) {
public JsonObject toJson(final PlayerCertificates playerCertificates) {
final JsonObject json = new JsonObject();
json.addProperty("expireTimeMs", result.expireTimeMs);
json.addProperty("publicKey", Base64.getEncoder().encodeToString(result.publicKey.getEncoded()));
json.addProperty("privateKey", Base64.getEncoder().encodeToString(result.privateKey.getEncoded()));
json.addProperty("publicKeySignature", Base64.getEncoder().encodeToString(result.publicKeySignature));
json.addProperty("legacyPublicKeySignature", Base64.getEncoder().encodeToString(result.legacyPublicKeySignature));
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.mcToken));
json.addProperty("expireTimeMs", playerCertificates.expireTimeMs);
json.addProperty("publicKey", Base64.getEncoder().encodeToString(playerCertificates.publicKey.getEncoded()));
json.addProperty("privateKey", Base64.getEncoder().encodeToString(playerCertificates.privateKey.getEncoded()));
json.addProperty("publicKeySignature", Base64.getEncoder().encodeToString(playerCertificates.publicKeySignature));
json.addProperty("legacyPublicKeySignature", Base64.getEncoder().encodeToString(playerCertificates.legacyPublicKeySignature));
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(playerCertificates.mcToken));
return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ protected FullJavaSession fromDeduplicatedJson(final JsonObject json) {
}

@Override
protected JsonObject toRawJson(final FullJavaSession result) {
protected JsonObject toRawJson(final FullJavaSession fullJavaSession) {
final JsonObject json = new JsonObject();
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.mcProfile));
if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(result.playerCertificates));
if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(fullJavaSession.mcProfile));
if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(fullJavaSession.playerCertificates));
return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public MsaCodeStep(final AbstractStep<?, I> prevStep, final String clientId, fin
}

@Override
public MsaCode applyStep(HttpClient httpClient, I prevResult) throws Exception {
public MsaCode applyStep(final HttpClient httpClient, final I prevResult) throws Exception {
throw new UnsupportedOperationException();
}

@Override
public MsaCode fromJson(JsonObject json) {
public MsaCode fromJson(final JsonObject json) {
return new MsaCode(
json.get("code").getAsString(),
json.get("clientId").getAsString(),
Expand All @@ -53,12 +53,12 @@ public MsaCode fromJson(JsonObject json) {
}

@Override
public JsonObject toJson(final MsaCode result) {
public JsonObject toJson(final MsaCode msaCode) {
final JsonObject json = new JsonObject();
json.addProperty("code", result.code);
json.addProperty("clientId", result.clientId);
json.addProperty("scope", result.scope);
json.addProperty("clientSecret", result.clientSecret);
json.addProperty("code", msaCode.code);
json.addProperty("clientId", msaCode.clientId);
json.addProperty("scope", msaCode.scope);
json.addProperty("clientSecret", msaCode.clientSecret);
return json;
}

Expand Down
Loading

0 comments on commit ac5167c

Please sign in to comment.