From eb2b7609a62805efae7300912b5cd5c43df854e0 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sun, 19 Nov 2023 21:47:05 +0100 Subject: [PATCH] Updated MinecraftAuth to 3.0.0 --- gradle.properties | 2 +- .../account/BedrockAccountHandler.java | 36 +++++++------------ .../screen/MixinConnectScreen_1.java | 19 +++++----- .../settings/impl/BedrockSettings.java | 20 +++++------ 4 files changed, 33 insertions(+), 44 deletions(-) diff --git a/gradle.properties b/gradle.properties index f23fca03..0295c8be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,7 +22,7 @@ viabedrock_version=0.0.3-SNAPSHOT vialoader_version=2.2.11-SNAPSHOT # RaphiMC Libraries -minecraftauth_version=2.1.7-SNAPSHOT +minecraftauth_version=3.0.0-SNAPSHOT raknet_transport_version=1.0.0.CR1-SNAPSHOT # Lenni0451 Libraries diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/account/BedrockAccountHandler.java b/src/main/java/de/florianmichael/viafabricplus/definition/account/BedrockAccountHandler.java index 1278d990..8af1d6d1 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/account/BedrockAccountHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/account/BedrockAccountHandler.java @@ -20,10 +20,9 @@ package de.florianmichael.viafabricplus.definition.account; import com.google.gson.JsonObject; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.util.FileSaver; -import net.raphimc.mcauth.MinecraftAuth; -import net.raphimc.mcauth.step.bedrock.StepMCChain; -import net.raphimc.mcauth.step.bedrock.StepPlayFabToken; -import net.raphimc.mcauth.util.MicrosoftConstants; +import net.raphimc.minecraftauth.MinecraftAuth; +import net.raphimc.minecraftauth.step.bedrock.session.StepFullBedrockSession; +import net.raphimc.minecraftauth.util.MicrosoftConstants; import org.apache.http.impl.client.CloseableHttpClient; public class BedrockAccountHandler extends FileSaver { @@ -34,8 +33,7 @@ public class BedrockAccountHandler extends FileSaver { BedrockAccountHandler.INSTANCE.init(); } - private StepMCChain.MCChain mcChain; - private StepPlayFabToken.PlayFabToken playFabToken; + private StepFullBedrockSession.FullBedrockSession bedrockSession; public BedrockAccountHandler() { super("bedrock.account"); @@ -43,39 +41,29 @@ public class BedrockAccountHandler extends FileSaver { @Override public void write(JsonObject object) { - if (mcChain == null) return; + if (bedrockSession == null) return; - object.add("mc-chain", mcChain.toJson()); - object.add("play-fab-token", playFabToken.toJson()); + object.add("bedrockSession", MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.toJson(bedrockSession)); } @Override public void read(JsonObject object) { try { - mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(object.get("mc-chain").getAsJsonObject()); - try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { - mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, mcChain); - } + bedrockSession = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(object.get("bedrockSession").getAsJsonObject()); - playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.fromJson(object.get("play-fab-token").getAsJsonObject()); try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { - playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.refresh(httpClient, playFabToken); + bedrockSession = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, bedrockSession); } } catch (Exception e) { ViaFabricPlus.LOGGER.warn("No Bedrock account could be found"); } } - public void setAccount(final StepMCChain.MCChain mcChain, final StepPlayFabToken.PlayFabToken playFabToken) { - this.mcChain = mcChain; - this.playFabToken = playFabToken; + public StepFullBedrockSession.FullBedrockSession getBedrockSession() { + return bedrockSession; } - public StepMCChain.MCChain getMcChain() { - return mcChain; - } - - public StepPlayFabToken.PlayFabToken getPlayFabToken() { - return playFabToken; + public void setBedrockSession(StepFullBedrockSession.FullBedrockSession bedrockSession) { + this.bedrockSession = bedrockSession; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinConnectScreen_1.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinConnectScreen_1.java index 66627213..02240d1e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinConnectScreen_1.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinConnectScreen_1.java @@ -21,7 +21,8 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ProfileKey; import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0; import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1; -import net.raphimc.mcauth.util.MicrosoftConstants; +import net.raphimc.minecraftauth.MinecraftAuth; +import net.raphimc.minecraftauth.util.MicrosoftConstants; import net.raphimc.vialoader.util.VersionEnum; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.definition.account.BedrockAccountHandler; @@ -37,7 +38,6 @@ import net.minecraft.network.ClientConnection; import net.minecraft.network.encryption.PlayerPublicKey; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket; -import net.raphimc.mcauth.step.bedrock.StepMCChain; import net.raphimc.viabedrock.protocol.storage.AuthChainData; import org.apache.http.impl.client.CloseableHttpClient; import org.spongepowered.asm.mixin.Final; @@ -98,20 +98,21 @@ public class MixinConnectScreen_1 { final VersionEnum targetVersion = ProtocolHack.getTargetVersion(connection.channel); if (targetVersion == VersionEnum.bedrockLatest) { - StepMCChain.MCChain account = BedrockAccountHandler.INSTANCE.getMcChain(); - if (account == null) return; - final UUID deviceId = account.prevResult().initialXblSession().prevResult2().id(); - final String playFabId = BedrockAccountHandler.INSTANCE.getPlayFabToken().playFabId(); + var bedrockSession = BedrockAccountHandler.INSTANCE.getBedrockSession(); + if (bedrockSession == null) return; try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { - account = new StepMCChain(null).applyStep(httpClient, account.prevResult()); + bedrockSession = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, bedrockSession); } catch (Exception e) { ViaFabricPlus.LOGGER.error("Failed to refresh Bedrock chain data. Please re-login to Bedrock!", e); return; } - userConnection.put(new AuthChainData(account.mojangJwt(), account.identityJwt(), account.publicKey(), account.privateKey(), deviceId, playFabId)); - ViaFabricPlus.LOGGER.info("Created AuthChainData for Bedrock authentication!"); + final var deviceId = bedrockSession.getMcChain().getXblXsts().getInitialXblSession().getXblDeviceToken().getId(); + final var playFabId = bedrockSession.getPlayFabToken().getPlayFabId(); + final var mcChain = bedrockSession.getMcChain(); + + userConnection.put(new AuthChainData(mcChain.getMojangJwt(), mcChain.getIdentityJwt(), mcChain.getPublicKey(), mcChain.getPrivateKey(), deviceId, playFabId)); return; } diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java index c02b6bc5..acedbfed 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/BedrockSettings.java @@ -28,9 +28,9 @@ import net.minecraft.client.gui.screen.NoticeScreen; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Util; -import net.raphimc.mcauth.MinecraftAuth; -import net.raphimc.mcauth.step.msa.StepMsaDeviceCode; -import net.raphimc.mcauth.util.MicrosoftConstants; +import net.raphimc.minecraftauth.MinecraftAuth; +import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode; +import net.raphimc.minecraftauth.util.MicrosoftConstants; import org.apache.http.impl.client.CloseableHttpClient; import java.net.URI; @@ -44,23 +44,23 @@ public class BedrockSettings extends SettingGroup { final var prevScreen = MinecraftClient.getInstance().currentScreen; try { try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { - final var mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> { + final var bedrockSession = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> { MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new ConfirmScreen(consumer -> { if (consumer) { - MinecraftClient.getInstance().keyboard.setClipboard(msaDeviceCode.userCode()); + MinecraftClient.getInstance().keyboard.setClipboard(msaDeviceCode.getUserCode()); } else { MinecraftClient.getInstance().setScreen(prevScreen); Thread.currentThread().interrupt(); } - }, Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.text", msaDeviceCode.userCode()), Text.translatable("misc.viafabricplus.copy"), Text.translatable("misc.viafabricplus.cancel")))); + }, Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.text", msaDeviceCode.getUserCode()), Text.translatable("misc.viafabricplus.copy"), Text.translatable("misc.viafabricplus.cancel")))); try { - Util.getOperatingSystem().open(new URI(msaDeviceCode.verificationUri())); + Util.getOperatingSystem().open(new URI(msaDeviceCode.getVerificationUri())); } catch (URISyntaxException e) { e.printStackTrace(); MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> Thread.currentThread().interrupt(), Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.error"), Text.translatable("misc.viafabricplus.cancel"), false))); } })); - BedrockAccountHandler.INSTANCE.setAccount(mcChain, MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, mcChain.prevResult().fullXblSession())); + BedrockAccountHandler.INSTANCE.setBedrockSession(bedrockSession); } RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(prevScreen)); } catch (Throwable e) { @@ -70,8 +70,8 @@ public class BedrockSettings extends SettingGroup { })) { @Override public MutableText displayValue() { - if (BedrockAccountHandler.INSTANCE.getMcChain() != null) { - return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getMcChain().displayName()); + if (BedrockAccountHandler.INSTANCE.getBedrockSession() != null) { + return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getBedrockSession().getMcChain().getDisplayName()); } return super.displayValue(); }