diff --git a/src/main/java/net/raphimc/minecraftauth/MinecraftAuth.java b/src/main/java/net/raphimc/minecraftauth/MinecraftAuth.java index ea8ee78..e5642b8 100644 --- a/src/main/java/net/raphimc/minecraftauth/MinecraftAuth.java +++ b/src/main/java/net/raphimc/minecraftauth/MinecraftAuth.java @@ -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; diff --git a/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepMCChain.java b/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepMCChain.java index b9e88b9..5a4d97b 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepMCChain.java +++ b/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepMCChain.java @@ -57,7 +57,7 @@ public StepMCChain(final AbstractStep> 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"); @@ -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(); @@ -90,7 +90,7 @@ 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(), @@ -98,17 +98,17 @@ public MCChain applyStep(final HttpClient httpClient, final StepXblXstsToken.Xbl 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 @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepPlayFabToken.java b/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepPlayFabToken.java index 78e6293..6513764 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepPlayFabToken.java +++ b/src/main/java/net/raphimc/minecraftauth/step/bedrock/StepPlayFabToken.java @@ -43,7 +43,7 @@ public StepPlayFabToken(final AbstractStep> 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(); @@ -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)); @@ -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 @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/bedrock/session/StepFullBedrockSession.java b/src/main/java/net/raphimc/minecraftauth/step/bedrock/session/StepFullBedrockSession.java index 567bb6f..fa148d9 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/bedrock/session/StepFullBedrockSession.java +++ b/src/main/java/net/raphimc/minecraftauth/step/bedrock/session/StepFullBedrockSession.java @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/java/StepMCProfile.java b/src/main/java/net/raphimc/minecraftauth/step/java/StepMCProfile.java index 0f686f7..e86b68d 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/java/StepMCProfile.java +++ b/src/main/java/net/raphimc/minecraftauth/step/java/StepMCProfile.java @@ -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 @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/java/StepMCToken.java b/src/main/java/net/raphimc/minecraftauth/step/java/StepMCToken.java index fdd1ae8..6ccfc00 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/java/StepMCToken.java +++ b/src/main/java/net/raphimc/minecraftauth/step/java/StepMCToken.java @@ -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 @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/java/StepPlayerCertificates.java b/src/main/java/net/raphimc/minecraftauth/step/java/StepPlayerCertificates.java index fdd1d2c..9c57019 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/java/StepPlayerCertificates.java +++ b/src/main/java/net/raphimc/minecraftauth/step/java/StepPlayerCertificates.java @@ -69,7 +69,7 @@ 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, @@ -77,15 +77,15 @@ public PlayerCertificates applyStep(final HttpClient httpClient, final StepMCTok 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 @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/java/session/StepFullJavaSession.java b/src/main/java/net/raphimc/minecraftauth/step/java/session/StepFullJavaSession.java index 20f9ff0..91b10d1 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/java/session/StepFullJavaSession.java +++ b/src/main/java/net/raphimc/minecraftauth/step/java/session/StepFullJavaSession.java @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/msa/MsaCodeStep.java b/src/main/java/net/raphimc/minecraftauth/step/msa/MsaCodeStep.java index 6a86f49..dba7f98 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/msa/MsaCodeStep.java +++ b/src/main/java/net/raphimc/minecraftauth/step/msa/MsaCodeStep.java @@ -38,12 +38,12 @@ public MsaCodeStep(final AbstractStep 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(), @@ -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; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/msa/StepCredentialsMsaCode.java b/src/main/java/net/raphimc/minecraftauth/step/msa/StepCredentialsMsaCode.java index 5fc3874..4c591a6 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/msa/StepCredentialsMsaCode.java +++ b/src/main/java/net/raphimc/minecraftauth/step/msa/StepCredentialsMsaCode.java @@ -48,21 +48,21 @@ public class StepCredentialsMsaCode extends MsaCodeStep postData = new ArrayList<>(); - postData.add(new BasicNameValuePair("login", prevResult.email)); - postData.add(new BasicNameValuePair("loginfmt", prevResult.email)); - postData.add(new BasicNameValuePair("passwd", prevResult.password)); + postData.add(new BasicNameValuePair("login", msaCredentials.email)); + postData.add(new BasicNameValuePair("loginfmt", msaCredentials.email)); + postData.add(new BasicNameValuePair("passwd", msaCredentials.password)); postData.add(new BasicNameValuePair("PPFT", sFTTag)); final HttpPost httpPost = new HttpPost(urlPost); @@ -91,9 +91,9 @@ public MsaCode applyStep(HttpClient httpClient, StepCredentialsMsaCode.MsaCreden httpPost.setEntity(new UrlEncodedFormEntity(postData, StandardCharsets.UTF_8)); final String code = httpClient.execute(httpPost, new MsaCredentialsResponseHandler(), context); - final MsaCode result = new MsaCode(code, this.clientId, this.scope, this.clientSecret, this.redirectUri); + final MsaCode msaCode = new MsaCode(code, this.clientId, this.scope, this.clientSecret, this.redirectUri); MinecraftAuth.LOGGER.info("Got MSA Code"); - return result; + return msaCode; } private URI getAuthenticationUrl() throws URISyntaxException { diff --git a/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowser.java b/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowser.java index 2799c7f..d78ce25 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowser.java +++ b/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowser.java @@ -50,27 +50,26 @@ public StepExternalBrowser(final String clientId, final String scope, final Stri } @Override - public StepExternalBrowser.ExternalBrowser applyStep(HttpClient httpClient, StepExternalBrowser.ExternalBrowserCallback prevResult) throws Exception { + public StepExternalBrowser.ExternalBrowser applyStep(final HttpClient httpClient, final StepExternalBrowser.ExternalBrowserCallback externalBrowserCallback) throws Exception { MinecraftAuth.LOGGER.info("Creating URL for MSA login via external browser..."); - if (prevResult == null) throw new IllegalStateException("Missing StepExternalBrowser.ExternalBrowserCallback input"); + if (externalBrowserCallback == null) throw new IllegalStateException("Missing StepExternalBrowser.ExternalBrowserCallback input"); try (final ServerSocket localServer = new ServerSocket(0)) { final int localPort = localServer.getLocalPort(); - final ExternalBrowser result = new ExternalBrowser( + final ExternalBrowser externalBrowser = new ExternalBrowser( this.getAuthenticationUrl(localPort), this.redirectUri + ":" + localPort, localPort); - - MinecraftAuth.LOGGER.info("Created external browser MSA authentication URL: " + result.authenticationUrl); - prevResult.callback.accept(result); - return result; + MinecraftAuth.LOGGER.info("Created external browser MSA authentication URL: " + externalBrowser.authenticationUrl); + externalBrowserCallback.callback.accept(externalBrowser); + return externalBrowser; } } @Override - public ExternalBrowser fromJson(JsonObject json) { + public ExternalBrowser fromJson(final JsonObject json) { return new ExternalBrowser( json.get("authenticationUrl").getAsString(), json.get("redirectUri").getAsString(), @@ -79,11 +78,11 @@ public ExternalBrowser fromJson(JsonObject json) { } @Override - public JsonObject toJson(final ExternalBrowser result) { + public JsonObject toJson(final ExternalBrowser externalBrowser) { final JsonObject json = new JsonObject(); - json.addProperty("authenticationUrl", result.authenticationUrl); - json.addProperty("redirectUri", result.redirectUri); - json.addProperty("port", result.port); + json.addProperty("authenticationUrl", externalBrowser.authenticationUrl); + json.addProperty("redirectUri", externalBrowser.redirectUri); + json.addProperty("port", externalBrowser.port); return json; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowserMsaCode.java b/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowserMsaCode.java index 81ae34c..e8db702 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowserMsaCode.java +++ b/src/main/java/net/raphimc/minecraftauth/step/msa/StepExternalBrowserMsaCode.java @@ -33,21 +33,21 @@ public class StepExternalBrowserMsaCode extends MsaCodeStep prevStep, String clientId, String scope, final int timeout) { + public StepExternalBrowserMsaCode(final AbstractStep prevStep, final String clientId, final String scope, final int timeout) { this(prevStep, clientId, scope, null, timeout); } - public StepExternalBrowserMsaCode(AbstractStep prevStep, String clientId, String scope, final String clientSecret, final int timeout) { + public StepExternalBrowserMsaCode(final AbstractStep prevStep, final String clientId, final String scope, final String clientSecret, final int timeout) { super(prevStep, clientId, scope, clientSecret); this.timeout = timeout; } @Override - public MsaCode applyStep(HttpClient httpClient, StepExternalBrowser.ExternalBrowser prevResult) throws Exception { + public MsaCode applyStep(final HttpClient httpClient, final StepExternalBrowser.ExternalBrowser externalBrowser) throws Exception { MinecraftAuth.LOGGER.info("Waiting for MSA login via external browser..."); - try (final ServerSocket localServer = new ServerSocket(prevResult.getPort())) { + try (final ServerSocket localServer = new ServerSocket(externalBrowser.getPort())) { localServer.setSoTimeout(this.timeout); try { try (final Socket client = localServer.accept()) { @@ -58,9 +58,9 @@ public MsaCode applyStep(HttpClient httpClient, StepExternalBrowser.ExternalBrow final Matcher m = Pattern.compile("code=([^&\\s]+)").matcher(get); if (m.find()) { - final MsaCode result = new MsaCode(m.group(1), this.clientId, this.scope, this.clientSecret, prevResult.getRedirectUri()); + final MsaCode msaCode = new MsaCode(m.group(1), this.clientId, this.scope, this.clientSecret, externalBrowser.getRedirectUri()); MinecraftAuth.LOGGER.info("Got MSA Code"); - return result; + return msaCode; } throw new RuntimeException("Could not find MSA code"); } diff --git a/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCode.java b/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCode.java index 14d519b..8330f19 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCode.java +++ b/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCode.java @@ -52,10 +52,10 @@ public StepMsaDeviceCode(final String clientId, final String scope) { } @Override - public MsaDeviceCode applyStep(HttpClient httpClient, StepMsaDeviceCode.MsaDeviceCodeCallback prevResult) throws Exception { + public MsaDeviceCode applyStep(final HttpClient httpClient, final StepMsaDeviceCode.MsaDeviceCodeCallback msaDeviceCodeCallback) throws Exception { MinecraftAuth.LOGGER.info("Getting device code for MSA login..."); - if (prevResult == null) throw new IllegalStateException("Missing StepMsaDeviceCode.MsaDeviceCodeCallback input"); + if (msaDeviceCodeCallback == null) throw new IllegalStateException("Missing StepMsaDeviceCode.MsaDeviceCodeCallback input"); final List postData = new ArrayList<>(); postData.add(new BasicNameValuePair("client_id", this.clientId)); @@ -67,20 +67,20 @@ public MsaDeviceCode applyStep(HttpClient httpClient, StepMsaDeviceCode.MsaDevic final String response = httpClient.execute(httpPost, new MsaResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final MsaDeviceCode result = new MsaDeviceCode( + final MsaDeviceCode msaDeviceCode = new MsaDeviceCode( System.currentTimeMillis() + obj.get("expires_in").getAsLong() * 1000, obj.get("interval").getAsLong() * 1000, obj.get("device_code").getAsString(), obj.get("user_code").getAsString(), obj.get("verification_uri").getAsString() ); - MinecraftAuth.LOGGER.info("Got MSA device code, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault())); - prevResult.callback.accept(result); - return result; + MinecraftAuth.LOGGER.info("Got MSA device code, expires: " + Instant.ofEpochMilli(msaDeviceCode.getExpireTimeMs()).atZone(ZoneId.systemDefault())); + msaDeviceCodeCallback.callback.accept(msaDeviceCode); + return msaDeviceCode; } @Override - public MsaDeviceCode fromJson(JsonObject json) { + public MsaDeviceCode fromJson(final JsonObject json) { return new MsaDeviceCode( json.get("expireTimeMs").getAsLong(), json.get("intervalMs").getAsLong(), @@ -91,13 +91,13 @@ public MsaDeviceCode fromJson(JsonObject json) { } @Override - public JsonObject toJson(final MsaDeviceCode result) { + public JsonObject toJson(final MsaDeviceCode msaDeviceCode) { final JsonObject json = new JsonObject(); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("intervalMs", result.intervalMs); - json.addProperty("deviceCode", result.deviceCode); - json.addProperty("userCode", result.userCode); - json.addProperty("verificationUrl", result.verificationUri); + json.addProperty("expireTimeMs", msaDeviceCode.expireTimeMs); + json.addProperty("intervalMs", msaDeviceCode.intervalMs); + json.addProperty("deviceCode", msaDeviceCode.deviceCode); + json.addProperty("userCode", msaDeviceCode.userCode); + json.addProperty("verificationUrl", msaDeviceCode.verificationUri); return json; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCodeMsaCode.java b/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCodeMsaCode.java index af96df1..2db2415 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCodeMsaCode.java +++ b/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaDeviceCodeMsaCode.java @@ -41,25 +41,25 @@ public class StepMsaDeviceCodeMsaCode extends MsaCodeStep prevStep, String clientId, String scope, final int timeout) { + public StepMsaDeviceCodeMsaCode(final AbstractStep prevStep, final String clientId, final String scope, final int timeout) { this(prevStep, clientId, scope, null, timeout); } - public StepMsaDeviceCodeMsaCode(AbstractStep prevStep, String clientId, String scope, final String clientSecret, final int timeout) { + public StepMsaDeviceCodeMsaCode(final AbstractStep prevStep, final String clientId, final String scope, final String clientSecret, final int timeout) { super(prevStep, clientId, scope, clientSecret); this.timeout = timeout; } @Override - public MsaCode applyStep(HttpClient httpClient, StepMsaDeviceCode.MsaDeviceCode prevResult) throws Exception { + public MsaCode applyStep(final HttpClient httpClient, final StepMsaDeviceCode.MsaDeviceCode msaDeviceCode) throws Exception { MinecraftAuth.LOGGER.info("Waiting for MSA login via device code..."); final long start = System.currentTimeMillis(); - while (!prevResult.isExpired() && System.currentTimeMillis() - start <= this.timeout) { + while (!msaDeviceCode.isExpired() && System.currentTimeMillis() - start <= this.timeout) { final List postData = new ArrayList<>(); postData.add(new BasicNameValuePair("client_id", this.clientId)); - postData.add(new BasicNameValuePair("device_code", prevResult.getDeviceCode())); + postData.add(new BasicNameValuePair("device_code", msaDeviceCode.getDeviceCode())); postData.add(new BasicNameValuePair("grant_type", "device_code")); final HttpPost httpPost = new HttpPost(TOKEN_URL); @@ -68,12 +68,12 @@ public MsaCode applyStep(HttpClient httpClient, StepMsaDeviceCode.MsaDeviceCode final String response = httpClient.execute(httpPost, new MsaResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final MsaCode result = new MsaCode(obj.get("refresh_token").getAsString(), this.clientId, this.scope, this.clientSecret, null); + final MsaCode msaCode = new MsaCode(obj.get("refresh_token").getAsString(), this.clientId, this.scope, this.clientSecret, null); MinecraftAuth.LOGGER.info("Got MSA Code"); - return result; + return msaCode; } catch (HttpResponseException e) { if (e.getStatusCode() == HttpStatus.SC_BAD_REQUEST && e.getReasonPhrase().startsWith("authorization_pending")) { - Thread.sleep(prevResult.getIntervalMs()); + Thread.sleep(msaDeviceCode.getIntervalMs()); continue; } throw e; diff --git a/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaToken.java b/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaToken.java index b3781ec..c412974 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaToken.java +++ b/src/main/java/net/raphimc/minecraftauth/step/msa/StepMsaToken.java @@ -40,24 +40,24 @@ public class StepMsaToken extends AbstractStep prevStep) { + public StepMsaToken(final AbstractStep prevStep) { super("msaToken", prevStep); } @Override - public MsaToken applyStep(HttpClient httpClient, MsaCodeStep.MsaCode prevResult) throws Exception { - return this.apply(httpClient, prevResult.getCode(), prevResult.getRedirectUri() != null ? "authorization_code" : "refresh_token", prevResult); + public MsaToken applyStep(final HttpClient httpClient, final MsaCodeStep.MsaCode msaCode) throws Exception { + return this.apply(httpClient, msaCode.getCode(), msaCode.getRedirectUri() != null ? "authorization_code" : "refresh_token", msaCode); } @Override - public MsaToken refresh(HttpClient httpClient, MsaToken result) throws Exception { - if (result.isExpired()) return this.apply(httpClient, result.getRefreshToken(), "refresh_token", result.getMsaCode()); + public MsaToken refresh(final HttpClient httpClient, final MsaToken msaToken) throws Exception { + if (msaToken.isExpired()) return this.apply(httpClient, msaToken.getRefreshToken(), "refresh_token", msaToken.getMsaCode()); - return result; + return msaToken; } @Override - public MsaToken fromJson(JsonObject json) { + public MsaToken fromJson(final JsonObject json) { final MsaCodeStep.MsaCode msaCode = this.prevStep != null ? this.prevStep.fromJson(json.getAsJsonObject("msaCode")) : null; return new MsaToken( json.get("userId").getAsString(), @@ -69,31 +69,31 @@ public MsaToken fromJson(JsonObject json) { } @Override - public JsonObject toJson(final MsaToken result) { + public JsonObject toJson(final MsaToken msaToken) { final JsonObject json = new JsonObject(); - json.addProperty("userId", result.userId); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("accessToken", result.accessToken); - json.addProperty("refreshToken", result.refreshToken); - if (this.prevStep != null) json.add("msaCode", this.prevStep.toJson(result.msaCode)); + json.addProperty("userId", msaToken.userId); + json.addProperty("expireTimeMs", msaToken.expireTimeMs); + json.addProperty("accessToken", msaToken.accessToken); + json.addProperty("refreshToken", msaToken.refreshToken); + if (this.prevStep != null) json.add("msaCode", this.prevStep.toJson(msaToken.msaCode)); return json; } - private MsaToken apply(final HttpClient httpClient, final String code, final String type, final MsaCodeStep.MsaCode prev_result) throws Exception { + private MsaToken apply(final HttpClient httpClient, final String code, final String type, final MsaCodeStep.MsaCode msaCode) throws Exception { MinecraftAuth.LOGGER.info("Getting MSA Token..."); final List postData = new ArrayList<>(); - postData.add(new BasicNameValuePair("client_id", prev_result.getClientId())); - postData.add(new BasicNameValuePair("scope", prev_result.getScope())); + postData.add(new BasicNameValuePair("client_id", msaCode.getClientId())); + postData.add(new BasicNameValuePair("scope", msaCode.getScope())); postData.add(new BasicNameValuePair("grant_type", type)); if (type.equals("refresh_token")) { postData.add(new BasicNameValuePair("refresh_token", code)); } else { postData.add(new BasicNameValuePair("code", code)); - postData.add(new BasicNameValuePair("redirect_uri", prev_result.getRedirectUri())); + postData.add(new BasicNameValuePair("redirect_uri", msaCode.getRedirectUri())); } - if (prev_result.getClientSecret() != null) { - postData.add(new BasicNameValuePair("client_secret", prev_result.getClientSecret())); + if (msaCode.getClientSecret() != null) { + postData.add(new BasicNameValuePair("client_secret", msaCode.getClientSecret())); } final HttpPost httpPost = new HttpPost(TOKEN_URL); @@ -101,15 +101,15 @@ private MsaToken apply(final HttpClient httpClient, final String code, final Str final String response = httpClient.execute(httpPost, new MsaResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final MsaToken result = new MsaToken( + final MsaToken msaToken = new MsaToken( obj.get("user_id").getAsString(), System.currentTimeMillis() + obj.get("expires_in").getAsLong() * 1000, obj.get("access_token").getAsString(), obj.get("refresh_token").getAsString(), - prev_result + msaCode ); - MinecraftAuth.LOGGER.info("Got MSA Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault())); - return result; + MinecraftAuth.LOGGER.info("Got MSA Token, expires: " + Instant.ofEpochMilli(msaToken.getExpireTimeMs()).atZone(ZoneId.systemDefault())); + return msaToken; } @Value diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblDeviceToken.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblDeviceToken.java index ad6488b..7b2f66b 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblDeviceToken.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblDeviceToken.java @@ -81,7 +81,7 @@ public XblDeviceToken applyStep(final HttpClient httpClient, final StepResult final String response = httpClient.execute(httpPost, new XblResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final XblDeviceToken result = new XblDeviceToken( + final XblDeviceToken xblDeviceToken = new XblDeviceToken( publicKey, privateKey, id, @@ -89,15 +89,15 @@ public XblDeviceToken applyStep(final HttpClient httpClient, final StepResult obj.get("Token").getAsString(), obj.getAsJsonObject("DisplayClaims").getAsJsonObject("xdi").get("did").getAsString() ); - MinecraftAuth.LOGGER.info("Got XBL Device Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault())); - return result; + MinecraftAuth.LOGGER.info("Got XBL Device Token, expires: " + Instant.ofEpochMilli(xblDeviceToken.getExpireTimeMs()).atZone(ZoneId.systemDefault())); + return xblDeviceToken; } @Override - public XblDeviceToken refresh(final HttpClient httpClient, final XblDeviceToken result) throws Exception { - if (result.isExpired()) return this.applyStep(httpClient, null); + public XblDeviceToken refresh(final HttpClient httpClient, final XblDeviceToken xblDeviceToken) throws Exception { + if (xblDeviceToken.isExpired()) return this.applyStep(httpClient, null); - return result; + return xblDeviceToken; } @Override @@ -113,14 +113,14 @@ public XblDeviceToken fromJson(final JsonObject json) { } @Override - public JsonObject toJson(final XblDeviceToken result) { + public JsonObject toJson(final XblDeviceToken xblDeviceToken) { 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("id", result.id.toString()); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("token", result.token); - json.addProperty("deviceId", result.deviceId); + json.addProperty("publicKey", Base64.getEncoder().encodeToString(xblDeviceToken.publicKey.getEncoded())); + json.addProperty("privateKey", Base64.getEncoder().encodeToString(xblDeviceToken.privateKey.getEncoded())); + json.addProperty("id", xblDeviceToken.id.toString()); + json.addProperty("expireTimeMs", xblDeviceToken.expireTimeMs); + json.addProperty("token", xblDeviceToken.token); + json.addProperty("deviceId", xblDeviceToken.deviceId); return json; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblSisuAuthentication.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblSisuAuthentication.java index aa0bb56..eafcc62 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblSisuAuthentication.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblSisuAuthentication.java @@ -69,7 +69,7 @@ public StepXblSisuAuthentication.XblSisuTokens applyStep(final HttpClient httpCl final String response = httpClient.execute(httpPost, new XblResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final XblSisuTokens result = new XblSisuTokens( + final XblSisuTokens xblSisuTokens = new XblSisuTokens( new XblSisuTokens.SisuTitleToken( Instant.parse(obj.getAsJsonObject("TitleToken").get("NotAfter").getAsString()).toEpochMilli(), obj.getAsJsonObject("TitleToken").get("Token").getAsString(), @@ -87,16 +87,15 @@ public StepXblSisuAuthentication.XblSisuTokens applyStep(final HttpClient httpCl ), initialXblSession ); - - MinecraftAuth.LOGGER.info("Got XBL Title+User+XSTS Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault())); - return result; + MinecraftAuth.LOGGER.info("Got XBL Title+User+XSTS Token, expires: " + Instant.ofEpochMilli(xblSisuTokens.getExpireTimeMs()).atZone(ZoneId.systemDefault())); + return xblSisuTokens; } @Override - public StepXblXstsToken.XblXsts refresh(final HttpClient httpClient, final StepXblXstsToken.XblXsts result) throws Exception { - if (result.isExpired()) return super.refresh(httpClient, result); + public StepXblXstsToken.XblXsts refresh(final HttpClient httpClient, final StepXblXstsToken.XblXsts xblXsts) throws Exception { + if (xblXsts.isExpired()) return super.refresh(httpClient, xblXsts); - return result; + return xblXsts; } @Override @@ -111,8 +110,8 @@ public StepXblSisuAuthentication.XblSisuTokens fromJson(final JsonObject json) { } @Override - public JsonObject toJson(final StepXblXstsToken.XblXsts result) { - final XblSisuTokens xblSisuTokens = (XblSisuTokens) result; + public JsonObject toJson(final StepXblXstsToken.XblXsts xblXsts) { + final XblSisuTokens xblSisuTokens = (XblSisuTokens) xblXsts; final JsonObject json = new JsonObject(); json.add("titleToken", XblSisuTokens.SisuTitleToken.toJson(xblSisuTokens.titleToken)); json.add("userToken", XblSisuTokens.SisuUserToken.toJson(xblSisuTokens.userToken)); @@ -178,11 +177,11 @@ public static SisuTitleToken fromJson(final JsonObject json) { ); } - public static JsonObject toJson(final SisuTitleToken result) { + public static JsonObject toJson(final SisuTitleToken sisuTitleToken) { final JsonObject json = new JsonObject(); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("token", result.token); - json.addProperty("titleId", result.titleId); + json.addProperty("expireTimeMs", sisuTitleToken.expireTimeMs); + json.addProperty("token", sisuTitleToken.token); + json.addProperty("titleId", sisuTitleToken.titleId); return json; } @@ -203,11 +202,11 @@ public static SisuUserToken fromJson(final JsonObject json) { ); } - public static JsonObject toJson(final SisuUserToken result) { + public static JsonObject toJson(final SisuUserToken sisuUserToken) { final JsonObject json = new JsonObject(); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("token", result.token); - json.addProperty("userHash", result.userHash); + json.addProperty("expireTimeMs", sisuUserToken.expireTimeMs); + json.addProperty("token", sisuUserToken.token); + json.addProperty("userHash", sisuUserToken.userHash); return json; } @@ -228,11 +227,11 @@ public static SisuXstsToken fromJson(final JsonObject json) { ); } - public static JsonObject toJson(final SisuXstsToken result) { + public static JsonObject toJson(final SisuXstsToken sisuXstsToken) { final JsonObject json = new JsonObject(); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("token", result.token); - json.addProperty("userHash", result.userHash); + json.addProperty("expireTimeMs", sisuXstsToken.expireTimeMs); + json.addProperty("token", sisuXstsToken.token); + json.addProperty("userHash", sisuXstsToken.userHash); return json; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblTitleToken.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblTitleToken.java index c144310..f5a6958 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblTitleToken.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblTitleToken.java @@ -66,21 +66,21 @@ public XblTitleToken applyStep(final HttpClient httpClient, final StepInitialXbl final String response = httpClient.execute(httpPost, new XblResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final XblTitleToken result = new XblTitleToken( + final XblTitleToken xblTitleToken = new XblTitleToken( Instant.parse(obj.get("NotAfter").getAsString()).toEpochMilli(), obj.get("Token").getAsString(), obj.getAsJsonObject("DisplayClaims").getAsJsonObject("xti").get("tid").getAsString(), initialXblSession ); - MinecraftAuth.LOGGER.info("Got XBL Title Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault())); - return result; + MinecraftAuth.LOGGER.info("Got XBL Title Token, expires: " + Instant.ofEpochMilli(xblTitleToken.getExpireTimeMs()).atZone(ZoneId.systemDefault())); + return xblTitleToken; } @Override - public XblTitleToken refresh(final HttpClient httpClient, final XblTitleToken result) throws Exception { - if (result.isExpired()) return super.refresh(httpClient, result); + public XblTitleToken refresh(final HttpClient httpClient, final XblTitleToken xblTitleToken) throws Exception { + if (xblTitleToken.isExpired()) return super.refresh(httpClient, xblTitleToken); - return result; + return xblTitleToken; } @Override @@ -95,12 +95,12 @@ public XblTitleToken fromJson(final JsonObject json) { } @Override - public JsonObject toJson(final XblTitleToken result) { + public JsonObject toJson(final XblTitleToken xblTitleToken) { final JsonObject json = new JsonObject(); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("token", result.token); - json.addProperty("titleId", result.titleId); - if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.initialXblSession)); + json.addProperty("expireTimeMs", xblTitleToken.expireTimeMs); + json.addProperty("token", xblTitleToken.token); + json.addProperty("titleId", xblTitleToken.titleId); + if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(xblTitleToken.initialXblSession)); return json; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblUserToken.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblUserToken.java index 2d80bd0..a71b9f8 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblUserToken.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblUserToken.java @@ -67,21 +67,21 @@ public XblUserToken applyStep(final HttpClient httpClient, final StepInitialXblS final String response = httpClient.execute(httpPost, new XblResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final XblUserToken result = new XblUserToken( + final XblUserToken xblUserToken = new XblUserToken( Instant.parse(obj.get("NotAfter").getAsString()).toEpochMilli(), obj.get("Token").getAsString(), obj.getAsJsonObject("DisplayClaims").getAsJsonArray("xui").get(0).getAsJsonObject().get("uhs").getAsString(), initialXblSession ); - MinecraftAuth.LOGGER.info("Got XBL User Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault())); - return result; + MinecraftAuth.LOGGER.info("Got XBL User Token, expires: " + Instant.ofEpochMilli(xblUserToken.getExpireTimeMs()).atZone(ZoneId.systemDefault())); + return xblUserToken; } @Override - public XblUserToken refresh(final HttpClient httpClient, final XblUserToken result) throws Exception { - if (result.isExpired()) return super.refresh(httpClient, result); + public XblUserToken refresh(final HttpClient httpClient, final XblUserToken xblUserToken) throws Exception { + if (xblUserToken.isExpired()) return super.refresh(httpClient, xblUserToken); - return result; + return xblUserToken; } @Override @@ -96,12 +96,12 @@ public XblUserToken fromJson(final JsonObject json) { } @Override - public JsonObject toJson(final XblUserToken result) { + public JsonObject toJson(final XblUserToken xblUserToken) { final JsonObject json = new JsonObject(); - json.addProperty("expireTimeMs", result.expireTimeMs); - json.addProperty("token", result.token); - json.addProperty("userHash", result.userHash); - if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.initialXblSession)); + json.addProperty("expireTimeMs", xblUserToken.expireTimeMs); + json.addProperty("token", xblUserToken.token); + json.addProperty("userHash", xblUserToken.userHash); + if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(xblUserToken.initialXblSession)); return json; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblXstsToken.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblXstsToken.java index 830bc7f..f64ef5b 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblXstsToken.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/StepXblXstsToken.java @@ -76,21 +76,21 @@ public XblXstsToken applyStep(final HttpClient httpClient, final StepFullXblSess final String response = httpClient.execute(httpPost, new XblResponseHandler()); final JsonObject obj = JsonParser.parseString(response).getAsJsonObject(); - final XblXstsToken result = new XblXstsToken( + final XblXstsToken xblXstsToken = new XblXstsToken( Instant.parse(obj.get("NotAfter").getAsString()).toEpochMilli(), obj.get("Token").getAsString(), obj.getAsJsonObject("DisplayClaims").getAsJsonArray("xui").get(0).getAsJsonObject().get("uhs").getAsString(), fullXblSession ); - MinecraftAuth.LOGGER.info("Got XSTS Token, expires: " + Instant.ofEpochMilli(result.getExpireTimeMs()).atZone(ZoneId.systemDefault())); - return result; + MinecraftAuth.LOGGER.info("Got XSTS Token, expires: " + Instant.ofEpochMilli(xblXstsToken.getExpireTimeMs()).atZone(ZoneId.systemDefault())); + return xblXstsToken; } @Override - public StepXblXstsToken.XblXsts refresh(final HttpClient httpClient, final StepXblXstsToken.XblXsts result) throws Exception { - if (result.isExpired()) return super.refresh(httpClient, result); + public StepXblXstsToken.XblXsts refresh(final HttpClient httpClient, final StepXblXstsToken.XblXsts xblXsts) throws Exception { + if (xblXsts.isExpired()) return super.refresh(httpClient, xblXsts); - return result; + return xblXsts; } @Override @@ -105,8 +105,8 @@ public XblXstsToken fromJson(final JsonObject json) { } @Override - public JsonObject toJson(final XblXsts result) { - final XblXstsToken xblXstsToken = (XblXstsToken) result; + public JsonObject toJson(final XblXsts xblXsts) { + final XblXstsToken xblXstsToken = (XblXstsToken) xblXsts; final JsonObject json = new JsonObject(); json.addProperty("expireTimeMs", xblXstsToken.expireTimeMs); json.addProperty("token", xblXstsToken.token); diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/adapter/StepXblXstsToFullXblSession.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/adapter/StepXblXstsToFullXblSession.java index 14bb5d4..f2b403b 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/adapter/StepXblXstsToFullXblSession.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/adapter/StepXblXstsToFullXblSession.java @@ -30,8 +30,8 @@ public StepXblXstsToFullXblSession(final AbstractStep prevResult) throws Exception { - return new FullXblSessionWrapper(prevResult); + public StepFullXblSession.FullXblSession applyStep(final HttpClient httpClient, final StepXblXstsToken.XblXsts xblXsts) throws Exception { + return new FullXblSessionWrapper(xblXsts); } @Override @@ -40,8 +40,8 @@ public StepFullXblSession.FullXblSession fromJson(final JsonObject json) { } @Override - public JsonObject toJson(final StepFullXblSession.FullXblSession result) { - final FullXblSessionWrapper fullXblSessionWrapper = (FullXblSessionWrapper) result; + public JsonObject toJson(final StepFullXblSession.FullXblSession fullXblSession) { + final FullXblSessionWrapper fullXblSessionWrapper = (FullXblSessionWrapper) fullXblSession; return this.prevStep.toJson(fullXblSessionWrapper.xblXsts); } diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepFullXblSession.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepFullXblSession.java index a489d69..2236cde 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepFullXblSession.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepFullXblSession.java @@ -48,10 +48,10 @@ protected FullXblSession fromDeduplicatedJson(final JsonObject json) { } @Override - protected JsonObject toRawJson(final FullXblSession result) { + protected JsonObject toRawJson(final FullXblSession fullXblSession) { final JsonObject json = new JsonObject(); - if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.xblUserToken)); - if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(result.xblTitleToken)); + if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(fullXblSession.xblUserToken)); + if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(fullXblSession.xblTitleToken)); return json; } diff --git a/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepInitialXblSession.java b/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepInitialXblSession.java index 76a402a..b19effa 100644 --- a/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepInitialXblSession.java +++ b/src/main/java/net/raphimc/minecraftauth/step/xbl/session/StepInitialXblSession.java @@ -45,10 +45,10 @@ public InitialXblSession fromJson(final JsonObject json) { } @Override - public JsonObject toJson(final InitialXblSession result) { + public JsonObject toJson(final InitialXblSession initialXblSession) { final JsonObject json = new JsonObject(); - if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(result.msaToken)); - if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(result.xblDeviceToken)); + if (this.prevStep != null) json.add(this.prevStep.name, this.prevStep.toJson(initialXblSession.msaToken)); + if (this.prevStep2 != null) json.add(this.prevStep2.name, this.prevStep2.toJson(initialXblSession.xblDeviceToken)); return json; }