Updated MinecraftAuth to 3.0.0

This commit is contained in:
FlorianMichael 2023-11-19 21:47:05 +01:00
parent a5a338ed52
commit eb2b7609a6
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
4 changed files with 33 additions and 44 deletions

View File

@ -22,7 +22,7 @@ viabedrock_version=0.0.3-SNAPSHOT
vialoader_version=2.2.11-SNAPSHOT vialoader_version=2.2.11-SNAPSHOT
# RaphiMC Libraries # RaphiMC Libraries
minecraftauth_version=2.1.7-SNAPSHOT minecraftauth_version=3.0.0-SNAPSHOT
raknet_transport_version=1.0.0.CR1-SNAPSHOT raknet_transport_version=1.0.0.CR1-SNAPSHOT
# Lenni0451 Libraries # Lenni0451 Libraries

View File

@ -20,10 +20,9 @@ package de.florianmichael.viafabricplus.definition.account;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.util.FileSaver; import de.florianmichael.viafabricplus.util.FileSaver;
import net.raphimc.mcauth.MinecraftAuth; import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.mcauth.step.bedrock.StepMCChain; import net.raphimc.minecraftauth.step.bedrock.session.StepFullBedrockSession;
import net.raphimc.mcauth.step.bedrock.StepPlayFabToken; import net.raphimc.minecraftauth.util.MicrosoftConstants;
import net.raphimc.mcauth.util.MicrosoftConstants;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
public class BedrockAccountHandler extends FileSaver { public class BedrockAccountHandler extends FileSaver {
@ -34,8 +33,7 @@ public class BedrockAccountHandler extends FileSaver {
BedrockAccountHandler.INSTANCE.init(); BedrockAccountHandler.INSTANCE.init();
} }
private StepMCChain.MCChain mcChain; private StepFullBedrockSession.FullBedrockSession bedrockSession;
private StepPlayFabToken.PlayFabToken playFabToken;
public BedrockAccountHandler() { public BedrockAccountHandler() {
super("bedrock.account"); super("bedrock.account");
@ -43,39 +41,29 @@ public class BedrockAccountHandler extends FileSaver {
@Override @Override
public void write(JsonObject object) { public void write(JsonObject object) {
if (mcChain == null) return; if (bedrockSession == null) return;
object.add("mc-chain", mcChain.toJson()); object.add("bedrockSession", MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.toJson(bedrockSession));
object.add("play-fab-token", playFabToken.toJson());
} }
@Override @Override
public void read(JsonObject object) { public void read(JsonObject object) {
try { try {
mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(object.get("mc-chain").getAsJsonObject()); bedrockSession = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(object.get("bedrockSession").getAsJsonObject());
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, mcChain);
}
playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.fromJson(object.get("play-fab-token").getAsJsonObject());
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { 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) { } catch (Exception e) {
ViaFabricPlus.LOGGER.warn("No Bedrock account could be found"); ViaFabricPlus.LOGGER.warn("No Bedrock account could be found");
} }
} }
public void setAccount(final StepMCChain.MCChain mcChain, final StepPlayFabToken.PlayFabToken playFabToken) { public StepFullBedrockSession.FullBedrockSession getBedrockSession() {
this.mcChain = mcChain; return bedrockSession;
this.playFabToken = playFabToken;
} }
public StepMCChain.MCChain getMcChain() { public void setBedrockSession(StepFullBedrockSession.FullBedrockSession bedrockSession) {
return mcChain; this.bedrockSession = bedrockSession;
}
public StepPlayFabToken.PlayFabToken getPlayFabToken() {
return playFabToken;
} }
} }

View File

@ -21,7 +21,8 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ProfileKey; 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_0;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1; 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 net.raphimc.vialoader.util.VersionEnum;
import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.account.BedrockAccountHandler; 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.encryption.PlayerPublicKey;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket; import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket;
import net.raphimc.mcauth.step.bedrock.StepMCChain;
import net.raphimc.viabedrock.protocol.storage.AuthChainData; import net.raphimc.viabedrock.protocol.storage.AuthChainData;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@ -98,20 +98,21 @@ public class MixinConnectScreen_1 {
final VersionEnum targetVersion = ProtocolHack.getTargetVersion(connection.channel); final VersionEnum targetVersion = ProtocolHack.getTargetVersion(connection.channel);
if (targetVersion == VersionEnum.bedrockLatest) { if (targetVersion == VersionEnum.bedrockLatest) {
StepMCChain.MCChain account = BedrockAccountHandler.INSTANCE.getMcChain(); var bedrockSession = BedrockAccountHandler.INSTANCE.getBedrockSession();
if (account == null) return; if (bedrockSession == null) return;
final UUID deviceId = account.prevResult().initialXblSession().prevResult2().id();
final String playFabId = BedrockAccountHandler.INSTANCE.getPlayFabToken().playFabId();
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { 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) { } catch (Exception e) {
ViaFabricPlus.LOGGER.error("Failed to refresh Bedrock chain data. Please re-login to Bedrock!", e); ViaFabricPlus.LOGGER.error("Failed to refresh Bedrock chain data. Please re-login to Bedrock!", e);
return; return;
} }
userConnection.put(new AuthChainData(account.mojangJwt(), account.identityJwt(), account.publicKey(), account.privateKey(), deviceId, playFabId)); final var deviceId = bedrockSession.getMcChain().getXblXsts().getInitialXblSession().getXblDeviceToken().getId();
ViaFabricPlus.LOGGER.info("Created AuthChainData for Bedrock authentication!"); 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; return;
} }

View File

@ -28,9 +28,9 @@ import net.minecraft.client.gui.screen.NoticeScreen;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.raphimc.mcauth.MinecraftAuth; import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.mcauth.step.msa.StepMsaDeviceCode; import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import net.raphimc.mcauth.util.MicrosoftConstants; import net.raphimc.minecraftauth.util.MicrosoftConstants;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import java.net.URI; import java.net.URI;
@ -44,23 +44,23 @@ public class BedrockSettings extends SettingGroup {
final var prevScreen = MinecraftClient.getInstance().currentScreen; final var prevScreen = MinecraftClient.getInstance().currentScreen;
try { try {
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { 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 -> { MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new ConfirmScreen(consumer -> {
if (consumer) { if (consumer) {
MinecraftClient.getInstance().keyboard.setClipboard(msaDeviceCode.userCode()); MinecraftClient.getInstance().keyboard.setClipboard(msaDeviceCode.getUserCode());
} else { } else {
MinecraftClient.getInstance().setScreen(prevScreen); MinecraftClient.getInstance().setScreen(prevScreen);
Thread.currentThread().interrupt(); 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 { try {
Util.getOperatingSystem().open(new URI(msaDeviceCode.verificationUri())); Util.getOperatingSystem().open(new URI(msaDeviceCode.getVerificationUri()));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); 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))); 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)); RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(prevScreen));
} catch (Throwable e) { } catch (Throwable e) {
@ -70,8 +70,8 @@ public class BedrockSettings extends SettingGroup {
})) { })) {
@Override @Override
public MutableText displayValue() { public MutableText displayValue() {
if (BedrockAccountHandler.INSTANCE.getMcChain() != null) { if (BedrockAccountHandler.INSTANCE.getBedrockSession() != null) {
return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getMcChain().displayName()); return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getBedrockSession().getMcChain().getDisplayName());
} }
return super.displayValue(); return super.displayValue();
} }