Updated MinecraftAuth

This commit is contained in:
RaphiMC 2024-01-19 21:35:08 +01:00
parent 68f715f140
commit 8654ebfafd
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
8 changed files with 19 additions and 34 deletions

View File

@ -91,7 +91,7 @@ dependencies {
include("net.raphimc.netminecraft:all:2.4.0-SNAPSHOT") { include("net.raphimc.netminecraft:all:2.4.0-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson" exclude group: "com.google.code.gson", module: "gson"
} }
include("net.raphimc:MinecraftAuth:3.1.0") { include("net.raphimc:MinecraftAuth:4.0.0-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson" exclude group: "com.google.code.gson", module: "gson"
exclude group: "org.slf4j", module: "slf4j-api" exclude group: "org.slf4j", module: "slf4j-api"
} }

View File

@ -20,12 +20,10 @@ package net.raphimc.viaproxy.saves.impl;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.raphimc.minecraftauth.util.MicrosoftConstants;
import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.saves.AbstractSave; import net.raphimc.viaproxy.saves.AbstractSave;
import net.raphimc.viaproxy.saves.impl.accounts.Account; import net.raphimc.viaproxy.saves.impl.accounts.Account;
import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount; import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -84,10 +82,8 @@ public class AccountsSaveV3 extends AbstractSave {
public void ensureRefreshed(final Account account) throws Throwable { public void ensureRefreshed(final Account account) throws Throwable {
synchronized (this) { synchronized (this) {
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { if (account.refresh()) {
if (account.refresh(httpClient)) { ViaProxy.getSaveManager().save();
ViaProxy.getSaveManager().save();
}
} }
} }
} }

View File

@ -19,7 +19,6 @@ package net.raphimc.viaproxy.saves.impl.accounts;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID; import java.util.UUID;
@ -42,7 +41,7 @@ public abstract class Account {
public abstract String getDisplayString(); public abstract String getDisplayString();
public boolean refresh(final CloseableHttpClient httpClient) throws Exception { public boolean refresh() throws Exception {
if (System.currentTimeMillis() - this.lastRefresh < 10_000L) { if (System.currentTimeMillis() - this.lastRefresh < 10_000L) {
return false; return false;
} }

View File

@ -25,7 +25,6 @@ import net.raphimc.minecraftauth.step.bedrock.StepPlayFabToken;
import net.raphimc.minecraftauth.step.bedrock.session.StepFullBedrockSession; import net.raphimc.minecraftauth.step.bedrock.session.StepFullBedrockSession;
import net.raphimc.minecraftauth.step.xbl.StepXblXstsToken; import net.raphimc.minecraftauth.step.xbl.StepXblXstsToken;
import net.raphimc.minecraftauth.util.MicrosoftConstants; import net.raphimc.minecraftauth.util.MicrosoftConstants;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID; import java.util.UUID;
@ -83,10 +82,10 @@ public class BedrockAccount extends Account {
} }
@Override @Override
public boolean refresh(CloseableHttpClient httpClient) throws Exception { public boolean refresh() throws Exception {
if (!super.refresh(httpClient)) return false; if (!super.refresh()) return false;
this.bedrockSession = DEVICE_CODE_LOGIN.refresh(httpClient, this.bedrockSession); this.bedrockSession = DEVICE_CODE_LOGIN.refresh(MinecraftAuth.createHttpClient(), this.bedrockSession);
return true; return true;
} }

View File

@ -24,7 +24,6 @@ import net.raphimc.minecraftauth.step.java.StepMCProfile;
import net.raphimc.minecraftauth.step.java.StepPlayerCertificates; import net.raphimc.minecraftauth.step.java.StepPlayerCertificates;
import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession; import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession;
import net.raphimc.minecraftauth.util.MicrosoftConstants; import net.raphimc.minecraftauth.util.MicrosoftConstants;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID; import java.util.UUID;
@ -78,10 +77,10 @@ public class MicrosoftAccount extends Account {
} }
@Override @Override
public boolean refresh(CloseableHttpClient httpClient) throws Exception { public boolean refresh() throws Exception {
if (!super.refresh(httpClient)) return false; if (!super.refresh()) return false;
this.javaSession = DEVICE_CODE_LOGIN.refresh(httpClient, this.javaSession); this.javaSession = DEVICE_CODE_LOGIN.refresh(MinecraftAuth.createHttpClient(), this.javaSession);
return true; return true;
} }

View File

@ -18,7 +18,6 @@
package net.raphimc.viaproxy.saves.impl.accounts; package net.raphimc.viaproxy.saves.impl.accounts;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.apache.http.impl.client.CloseableHttpClient;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.UUID; import java.util.UUID;
@ -62,7 +61,7 @@ public class OfflineAccount extends Account {
} }
@Override @Override
public boolean refresh(CloseableHttpClient httpClient) { public boolean refresh() {
return false; return false;
} }

View File

@ -19,8 +19,8 @@ package net.raphimc.viaproxy.ui.impl;
import net.lenni0451.commons.swing.GBC; import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler; import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode; import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import net.raphimc.minecraftauth.util.MicrosoftConstants;
import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options; import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.saves.impl.accounts.Account; import net.raphimc.viaproxy.saves.impl.accounts.Account;
@ -32,7 +32,6 @@ import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UIInitEvent; import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.ui.popups.AddAccountPopup; import net.raphimc.viaproxy.ui.popups.AddAccountPopup;
import net.raphimc.viaproxy.util.TFunction; import net.raphimc.viaproxy.util.TFunction;
import org.apache.http.impl.client.CloseableHttpClient;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -179,9 +178,7 @@ public class AccountsTab extends AUITab {
this.addMicrosoftAccountButton.addActionListener(event -> { this.addMicrosoftAccountButton.addActionListener(event -> {
this.addMicrosoftAccountButton.setEnabled(false); this.addMicrosoftAccountButton.setEnabled(false);
this.handleLogin(msaDeviceCodeConsumer -> { this.handleLogin(msaDeviceCodeConsumer -> {
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { return new MicrosoftAccount(MicrosoftAccount.DEVICE_CODE_LOGIN.getFromInput(MinecraftAuth.createHttpClient(), new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer)));
return new MicrosoftAccount(MicrosoftAccount.DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer)));
}
}); });
}); });
addButtons.add(this.addMicrosoftAccountButton); addButtons.add(this.addMicrosoftAccountButton);
@ -191,9 +188,7 @@ public class AccountsTab extends AUITab {
this.addBedrockAccountButton.addActionListener(event -> { this.addBedrockAccountButton.addActionListener(event -> {
this.addBedrockAccountButton.setEnabled(false); this.addBedrockAccountButton.setEnabled(false);
this.handleLogin(msaDeviceCodeConsumer -> { this.handleLogin(msaDeviceCodeConsumer -> {
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { return new BedrockAccount(BedrockAccount.DEVICE_CODE_LOGIN.getFromInput(MinecraftAuth.createHttpClient(), new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer)));
return new BedrockAccount(BedrockAccount.DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer)));
}
}); });
}); });
addButtons.add(this.addBedrockAccountButton); addButtons.add(this.addBedrockAccountButton);

View File

@ -20,12 +20,12 @@ package net.raphimc.viaproxy.ui.impl;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import net.lenni0451.commons.swing.GBC; import net.lenni0451.commons.swing.GBC;
import net.lenni0451.commons.swing.layouts.VerticalLayout; import net.lenni0451.commons.swing.layouts.VerticalLayout;
import net.raphimc.minecraftauth.responsehandler.exception.RealmsResponseException; import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.responsehandler.exception.RealmsRequestException;
import net.raphimc.minecraftauth.service.realms.AbstractRealmsService; import net.raphimc.minecraftauth.service.realms.AbstractRealmsService;
import net.raphimc.minecraftauth.service.realms.BedrockRealmsService; import net.raphimc.minecraftauth.service.realms.BedrockRealmsService;
import net.raphimc.minecraftauth.service.realms.JavaRealmsService; import net.raphimc.minecraftauth.service.realms.JavaRealmsService;
import net.raphimc.minecraftauth.service.realms.model.RealmsWorld; import net.raphimc.minecraftauth.service.realms.model.RealmsWorld;
import net.raphimc.minecraftauth.util.MicrosoftConstants;
import net.raphimc.viabedrock.protocol.data.ProtocolConstants; import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.ViaProxy;
@ -37,7 +37,6 @@ import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.I18n; import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI; import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.viaproxy.util.logging.Logger;
import org.apache.http.impl.client.CloseableHttpClient;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -48,7 +47,6 @@ public class RealmsTab extends AUITab {
private static final VersionEnum LATEST_JAVA_RELEASE; private static final VersionEnum LATEST_JAVA_RELEASE;
private static final VersionEnum LATEST_JAVA_SNAPSHOT; private static final VersionEnum LATEST_JAVA_SNAPSHOT;
private static final CloseableHttpClient HTTP_CLIENT = MicrosoftConstants.createHttpClient();
static { static {
VersionEnum latestVersion = null; VersionEnum latestVersion = null;
@ -108,10 +106,10 @@ public class RealmsTab extends AUITab {
ViaProxy.getSaveManager().accountsSave.ensureRefreshed(this.currentAccount); ViaProxy.getSaveManager().accountsSave.ensureRefreshed(this.currentAccount);
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (this.currentAccount instanceof MicrosoftAccount account) { if (this.currentAccount instanceof MicrosoftAccount account) {
final JavaRealmsService realmsService = new JavaRealmsService(HTTP_CLIENT, Iterables.getLast(this.currentSelectedJavaVersion.getProtocol().getIncludedVersions()), account.getMcProfile()); final JavaRealmsService realmsService = new JavaRealmsService(MinecraftAuth.createHttpClient(), Iterables.getLast(this.currentSelectedJavaVersion.getProtocol().getIncludedVersions()), account.getMcProfile());
this.loadRealms(realmsService, body, statusLabel); this.loadRealms(realmsService, body, statusLabel);
} else if (this.currentAccount instanceof BedrockAccount account) { } else if (this.currentAccount instanceof BedrockAccount account) {
final BedrockRealmsService realmsService = new BedrockRealmsService(HTTP_CLIENT, ProtocolConstants.BEDROCK_VERSION_NAME, account.getRealmsXsts()); final BedrockRealmsService realmsService = new BedrockRealmsService(MinecraftAuth.createHttpClient(), ProtocolConstants.BEDROCK_VERSION_NAME, account.getRealmsXsts());
this.loadRealms(realmsService, body, statusLabel); this.loadRealms(realmsService, body, statusLabel);
} else { } else {
statusLabel.setText(I18n.get("tab.realms.unsupported_account")); statusLabel.setText(I18n.get("tab.realms.unsupported_account"));
@ -231,7 +229,7 @@ public class RealmsTab extends AUITab {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
join.setEnabled(true); join.setEnabled(true);
join.setText(I18n.get("tab.realms.join")); join.setText(I18n.get("tab.realms.join"));
if (realmsService instanceof JavaRealmsService javaRealmsService && cause instanceof RealmsResponseException realmsResponseException && realmsResponseException.getErrorCode() == RealmsResponseException.TOS_NOT_ACCEPTED) { if (realmsService instanceof JavaRealmsService javaRealmsService && cause instanceof RealmsRequestException realmsRequestException && realmsRequestException.getErrorCode() == RealmsRequestException.TOS_NOT_ACCEPTED) {
final int chosen = JOptionPane.showConfirmDialog(ViaProxy.getUI(), I18n.get("tab.realms.accept_tos", "https://aka.ms/MinecraftRealmsTerms"), "ViaProxy", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); final int chosen = JOptionPane.showConfirmDialog(ViaProxy.getUI(), I18n.get("tab.realms.accept_tos", "https://aka.ms/MinecraftRealmsTerms"), "ViaProxy", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (chosen == JOptionPane.YES_OPTION) { if (chosen == JOptionPane.YES_OPTION) {
javaRealmsService.acceptTos(); javaRealmsService.acceptTos();