Updated MinecraftAuth to 3.0.0

This commit is contained in:
RaphiMC 2023-11-19 20:17:16 +01:00
parent b3855008d9
commit 98cef186ff
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
11 changed files with 84 additions and 127 deletions

View File

@ -88,7 +88,7 @@ dependencies {
include("net.raphimc.netminecraft:all:2.3.7-SNAPSHOT") { include("net.raphimc.netminecraft:all:2.3.7-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson" exclude group: "com.google.code.gson", module: "gson"
} }
include("net.raphimc:MinecraftAuth:2.1.7-SNAPSHOT") { include("net.raphimc:MinecraftAuth:3.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

@ -25,8 +25,8 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3; import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.raphimc.mcauth.step.bedrock.StepMCChain; import net.raphimc.minecraftauth.step.bedrock.StepMCChain;
import net.raphimc.mcauth.step.java.StepPlayerCertificates; import net.raphimc.minecraftauth.step.java.StepPlayerCertificates;
import net.raphimc.netminecraft.packet.PacketTypes; import net.raphimc.netminecraft.packet.PacketTypes;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_19_3; import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_19_3;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_20_2; import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_20_2;
@ -66,29 +66,29 @@ public class ExternalInterface {
if (Options.CHAT_SIGNING && proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_19) && account instanceof MicrosoftAccount microsoftAccount) { if (Options.CHAT_SIGNING && proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_19) && account instanceof MicrosoftAccount microsoftAccount) {
final StepPlayerCertificates.PlayerCertificates playerCertificates = microsoftAccount.getPlayerCertificates(); final StepPlayerCertificates.PlayerCertificates playerCertificates = microsoftAccount.getPlayerCertificates();
final Instant expiresAt = Instant.ofEpochMilli(playerCertificates.expireTimeMs()); final Instant expiresAt = Instant.ofEpochMilli(playerCertificates.getExpireTimeMs());
final long expiresAtMillis = playerCertificates.expireTimeMs(); final long expiresAtMillis = playerCertificates.getExpireTimeMs();
final PublicKey publicKey = playerCertificates.publicKey(); final PublicKey publicKey = playerCertificates.getPublicKey();
final byte[] publicKeyBytes = publicKey.getEncoded(); final byte[] publicKeyBytes = publicKey.getEncoded();
final byte[] keySignature = playerCertificates.publicKeySignature(); final byte[] keySignature = playerCertificates.getPublicKeySignature();
final PrivateKey privateKey = playerCertificates.privateKey(); final PrivateKey privateKey = playerCertificates.getPrivateKey();
final UUID uuid = proxyConnection.getGameProfile().getId(); final UUID uuid = proxyConnection.getGameProfile().getId();
byte[] loginHelloKeySignature = keySignature; byte[] loginHelloKeySignature = keySignature;
if (proxyConnection.getClientVersion().equals(VersionEnum.r1_19)) { if (proxyConnection.getClientVersion().equals(VersionEnum.r1_19)) {
loginHelloKeySignature = playerCertificates.legacyPublicKeySignature(); loginHelloKeySignature = playerCertificates.getLegacyPublicKeySignature();
} }
proxyConnection.setLoginHelloPacket(new C2SLoginHelloPacket1_20_2(proxyConnection.getGameProfile().getName(), expiresAt, publicKey, loginHelloKeySignature, proxyConnection.getGameProfile().getId())); proxyConnection.setLoginHelloPacket(new C2SLoginHelloPacket1_20_2(proxyConnection.getGameProfile().getName(), expiresAt, publicKey, loginHelloKeySignature, proxyConnection.getGameProfile().getId()));
user.put(new ChatSession1_19_0(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, playerCertificates.legacyPublicKeySignature()))); user.put(new ChatSession1_19_0(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, playerCertificates.getLegacyPublicKeySignature())));
user.put(new ChatSession1_19_1(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature))); user.put(new ChatSession1_19_1(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature)));
user.put(new ChatSession1_19_3(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature))); user.put(new ChatSession1_19_3(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature)));
} else if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest) && account instanceof BedrockAccount bedrockAccount) { } else if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest) && account instanceof BedrockAccount bedrockAccount) {
final StepMCChain.MCChain mcChain = bedrockAccount.getMcChain(); final StepMCChain.MCChain mcChain = bedrockAccount.getMcChain();
final UUID deviceId = mcChain.prevResult().initialXblSession().prevResult2().id(); final UUID deviceId = mcChain.getXblXsts().getInitialXblSession().getXblDeviceToken().getId();
final String playFabId = bedrockAccount.getPlayFabToken().playFabId(); final String playFabId = bedrockAccount.getPlayFabToken().getPlayFabId();
user.put(new AuthChainData(mcChain.mojangJwt(), mcChain.identityJwt(), mcChain.publicKey(), mcChain.privateKey(), deviceId, playFabId)); user.put(new AuthChainData(mcChain.getMojangJwt(), mcChain.getIdentityJwt(), mcChain.getPublicKey(), mcChain.getPrivateKey(), deviceId, playFabId));
} }
} }
@ -116,7 +116,7 @@ public class ExternalInterface {
} }
} else if (proxyConnection.getUserOptions().account() instanceof MicrosoftAccount microsoftAccount) { } else if (proxyConnection.getUserOptions().account() instanceof MicrosoftAccount microsoftAccount) {
try { try {
AuthLibServices.SESSION_SERVICE.joinServer(microsoftAccount.getGameProfile(), microsoftAccount.getMcProfile().prevResult().prevResult().access_token(), serverIdHash); AuthLibServices.SESSION_SERVICE.joinServer(microsoftAccount.getGameProfile(), microsoftAccount.getMcProfile().getMcToken().getAccessToken(), serverIdHash);
} catch (Throwable e) { } catch (Throwable e) {
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again in a couple of seconds."); proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again in a couple of seconds.");
} }

View File

@ -21,7 +21,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.lenni0451.reflect.stream.RStream; import net.lenni0451.reflect.stream.RStream;
import net.raphimc.viaproxy.saves.impl.NewAccountsSave; import net.raphimc.viaproxy.saves.impl.AccountsSaveV3;
import net.raphimc.viaproxy.saves.impl.UISave; import net.raphimc.viaproxy.saves.impl.UISave;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.viaproxy.util.logging.Logger;
@ -34,7 +34,7 @@ public class SaveManager {
private static final File SAVE_FILE = new File("saves.json"); private static final File SAVE_FILE = new File("saves.json");
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
public final NewAccountsSave accountsSave = new NewAccountsSave(); public final AccountsSaveV3 accountsSave = new AccountsSaveV3();
public final UISave uiSave = new UISave(); public final UISave uiSave = new UISave();
public SaveManager() { public SaveManager() {

View File

@ -20,7 +20,7 @@ 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.mcauth.util.MicrosoftConstants; 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;
@ -31,12 +31,12 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class NewAccountsSave extends AbstractSave { public class AccountsSaveV3 extends AbstractSave {
private List<Account> accounts = new ArrayList<>(); private List<Account> accounts = new ArrayList<>();
public NewAccountsSave() { public AccountsSaveV3() {
super("new_accounts"); super("accountsV3");
} }
@Override @Override
@ -44,7 +44,7 @@ public class NewAccountsSave extends AbstractSave {
this.accounts = new ArrayList<>(); this.accounts = new ArrayList<>();
for (JsonElement element : jsonElement.getAsJsonArray()) { for (JsonElement element : jsonElement.getAsJsonArray()) {
final JsonObject jsonObject = element.getAsJsonObject(); final JsonObject jsonObject = element.getAsJsonObject();
final String type = jsonObject.get("account_type").getAsString(); final String type = jsonObject.get("accountType").getAsString();
final Class<?> clazz = Class.forName(type); final Class<?> clazz = Class.forName(type);
final Account account = (Account) clazz.getConstructor(JsonObject.class).newInstance(jsonObject); final Account account = (Account) clazz.getConstructor(JsonObject.class).newInstance(jsonObject);
this.accounts.add(account); this.accounts.add(account);
@ -56,7 +56,7 @@ public class NewAccountsSave extends AbstractSave {
final JsonArray array = new JsonArray(); final JsonArray array = new JsonArray();
for (Account account : this.accounts) { for (Account account : this.accounts) {
final JsonObject jsonObject = account.toJson(); final JsonObject jsonObject = account.toJson();
jsonObject.addProperty("account_type", account.getClass().getName()); jsonObject.addProperty("accountType", account.getClass().getName());
array.add(jsonObject); array.add(jsonObject);
} }
return array; return array;

View File

@ -18,60 +18,63 @@
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 net.raphimc.mcauth.MinecraftAuth; import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.mcauth.step.bedrock.StepMCChain; import net.raphimc.minecraftauth.step.AbstractStep;
import net.raphimc.mcauth.step.bedrock.StepPlayFabToken; import net.raphimc.minecraftauth.step.bedrock.StepMCChain;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.minecraftauth.step.bedrock.StepPlayFabToken;
import net.raphimc.minecraftauth.step.bedrock.session.StepFullBedrockSession;
import net.raphimc.minecraftauth.step.xbl.StepXblXstsToken;
import net.raphimc.minecraftauth.util.MicrosoftConstants;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID; import java.util.UUID;
public class BedrockAccount extends Account { public class BedrockAccount extends Account {
private StepMCChain.MCChain mcChain; public static final AbstractStep<?, StepFullBedrockSession.FullBedrockSession> DEVICE_CODE_LOGIN = MinecraftAuth.builder()
private StepPlayFabToken.PlayFabToken playFabToken; .withClientId(MicrosoftConstants.BEDROCK_ANDROID_TITLE_ID).withScope(MicrosoftConstants.SCOPE_TITLE_AUTH)
.deviceCode()
.withDeviceToken("Android")
.sisuTitleAuthentication(MicrosoftConstants.BEDROCK_XSTS_RELYING_PARTY)
.buildMinecraftBedrockChainStep(true, true);
public BedrockAccount(final JsonObject jsonObject) throws Exception { private StepFullBedrockSession.FullBedrockSession bedrockSession;
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("mc_chain"));
if (jsonObject.has("play_fab_token")) { public BedrockAccount(final JsonObject jsonObject) {
try { this.bedrockSession = DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("bedrockSession"));
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.fromJson(jsonObject.getAsJsonObject("play_fab_token"));
} catch (Throwable e) {
Logger.LOGGER.warn("Failed to load PlayFab token for Bedrock account. It will be regenerated.", e);
}
}
} }
public BedrockAccount(final StepMCChain.MCChain mcChain) { public BedrockAccount(final StepFullBedrockSession.FullBedrockSession bedrockSession) {
this.mcChain = mcChain; this.bedrockSession = bedrockSession;
} }
@Override @Override
public JsonObject toJson() { public JsonObject toJson() {
final JsonObject jsonObject = new JsonObject(); final JsonObject jsonObject = new JsonObject();
jsonObject.add("mc_chain", this.mcChain.toJson()); jsonObject.add("bedrockSession", DEVICE_CODE_LOGIN.toJson(this.bedrockSession));
if (this.playFabToken != null) {
jsonObject.add("play_fab_token", this.playFabToken.toJson());
}
return jsonObject; return jsonObject;
} }
@Override @Override
public String getName() { public String getName() {
return this.mcChain.displayName(); return this.bedrockSession.getMcChain().getDisplayName();
} }
@Override @Override
public UUID getUUID() { public UUID getUUID() {
return this.mcChain.id(); return this.bedrockSession.getMcChain().getId();
} }
public StepMCChain.MCChain getMcChain() { public StepMCChain.MCChain getMcChain() {
return this.mcChain; return this.bedrockSession.getMcChain();
} }
public StepPlayFabToken.PlayFabToken getPlayFabToken() { public StepPlayFabToken.PlayFabToken getPlayFabToken() {
return this.playFabToken; return this.bedrockSession.getPlayFabToken();
}
public StepXblXstsToken.XblXsts<?> getRealmsXsts() {
return this.bedrockSession.getRealmsXsts();
} }
@Override @Override
@ -83,18 +86,7 @@ public class BedrockAccount extends Account {
public boolean refresh(CloseableHttpClient httpClient) throws Exception { public boolean refresh(CloseableHttpClient httpClient) throws Exception {
if (!super.refresh(httpClient)) return false; if (!super.refresh(httpClient)) return false;
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcChain); this.bedrockSession = DEVICE_CODE_LOGIN.refresh(httpClient, this.bedrockSession);
try {
if (this.playFabToken == null) {
throw new NullPointerException();
}
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.refresh(httpClient, this.playFabToken);
} catch (Throwable e) {
this.playFabToken = null;
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, this.mcChain.prevResult().fullXblSession());
}
return true; return true;
} }

View File

@ -18,60 +18,58 @@
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 net.raphimc.mcauth.MinecraftAuth; import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.mcauth.step.java.StepMCProfile; import net.raphimc.minecraftauth.step.AbstractStep;
import net.raphimc.mcauth.step.java.StepPlayerCertificates; import net.raphimc.minecraftauth.step.java.StepMCProfile;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.minecraftauth.step.java.StepPlayerCertificates;
import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession;
import net.raphimc.minecraftauth.util.MicrosoftConstants;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID; import java.util.UUID;
public class MicrosoftAccount extends Account { public class MicrosoftAccount extends Account {
private StepMCProfile.MCProfile mcProfile; public static final AbstractStep<?, StepFullJavaSession.FullJavaSession> DEVICE_CODE_LOGIN = MinecraftAuth.builder()
private StepPlayerCertificates.PlayerCertificates playerCertificates; .withClientId(MicrosoftConstants.JAVA_TITLE_ID).withScope(MicrosoftConstants.SCOPE_TITLE_AUTH)
.deviceCode()
.withDeviceToken("Win32")
.sisuTitleAuthentication(MicrosoftConstants.JAVA_XSTS_RELYING_PARTY)
.buildMinecraftJavaProfileStep(true);
public MicrosoftAccount(final JsonObject jsonObject) throws Throwable { private StepFullJavaSession.FullJavaSession javaSession;
this.mcProfile = MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("mc_profile"));
if (jsonObject.has("player_certificates")) { public MicrosoftAccount(final JsonObject jsonObject) {
try { this.javaSession = DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("javaSession"));
this.playerCertificates = MinecraftAuth.JAVA_PLAYER_CERTIFICATES.fromJson(jsonObject.getAsJsonObject("player_certificates"));
} catch (Throwable e) {
Logger.LOGGER.warn("Failed to load player certificates for Microsoft account. They will be regenerated.", e);
}
}
} }
public MicrosoftAccount(final StepMCProfile.MCProfile mcProfile) { public MicrosoftAccount(final StepFullJavaSession.FullJavaSession javaSession) {
this.mcProfile = mcProfile; this.javaSession = javaSession;
} }
@Override @Override
public JsonObject toJson() { public JsonObject toJson() {
final JsonObject jsonObject = new JsonObject(); final JsonObject jsonObject = new JsonObject();
jsonObject.add("mc_profile", this.mcProfile.toJson()); jsonObject.add("javaSession", DEVICE_CODE_LOGIN.toJson(this.javaSession));
if (this.playerCertificates != null) {
jsonObject.add("player_certificates", this.playerCertificates.toJson());
}
return jsonObject; return jsonObject;
} }
@Override @Override
public String getName() { public String getName() {
return this.mcProfile.name(); return this.javaSession.getMcProfile().getName();
} }
@Override @Override
public UUID getUUID() { public UUID getUUID() {
return this.mcProfile.id(); return this.javaSession.getMcProfile().getId();
} }
public StepMCProfile.MCProfile getMcProfile() { public StepMCProfile.MCProfile getMcProfile() {
return this.mcProfile; return this.javaSession.getMcProfile();
} }
public StepPlayerCertificates.PlayerCertificates getPlayerCertificates() { public StepPlayerCertificates.PlayerCertificates getPlayerCertificates() {
return this.playerCertificates; return this.javaSession.getPlayerCertificates();
} }
@Override @Override
@ -83,18 +81,7 @@ public class MicrosoftAccount extends Account {
public boolean refresh(CloseableHttpClient httpClient) throws Exception { public boolean refresh(CloseableHttpClient httpClient) throws Exception {
if (!super.refresh(httpClient)) return false; if (!super.refresh(httpClient)) return false;
this.mcProfile = MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcProfile); this.javaSession = DEVICE_CODE_LOGIN.refresh(httpClient, this.javaSession);
try {
if (this.playerCertificates == null) {
throw new NullPointerException();
}
this.playerCertificates = MinecraftAuth.JAVA_PLAYER_CERTIFICATES.refresh(httpClient, this.playerCertificates);
} catch (Throwable e) {
this.playerCertificates = null;
this.playerCertificates = MinecraftAuth.JAVA_PLAYER_CERTIFICATES.getFromInput(httpClient, this.mcProfile.prevResult().prevResult());
}
return true; return true;
} }

View File

@ -18,9 +18,8 @@
package net.raphimc.viaproxy.ui.impl; package net.raphimc.viaproxy.ui.impl;
import net.lenni0451.lambdaevents.EventHandler; import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.mcauth.MinecraftAuth; import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import net.raphimc.mcauth.step.msa.StepMsaDeviceCode; import net.raphimc.minecraftauth.util.MicrosoftConstants;
import net.raphimc.mcauth.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;
@ -181,7 +180,7 @@ public class AccountsTab extends AUITab {
this.addMicrosoftAccountButton.setEnabled(false); this.addMicrosoftAccountButton.setEnabled(false);
this.handleLogin(msaDeviceCodeConsumer -> { this.handleLogin(msaDeviceCodeConsumer -> {
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
return new MicrosoftAccount(MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer))); return new MicrosoftAccount(MicrosoftAccount.DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer)));
} }
}); });
}); });
@ -193,7 +192,7 @@ public class AccountsTab extends AUITab {
this.addBedrockAccountButton.setEnabled(false); this.addBedrockAccountButton.setEnabled(false);
this.handleLogin(msaDeviceCodeConsumer -> { this.handleLogin(msaDeviceCodeConsumer -> {
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) { try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
return new BedrockAccount(MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer))); return new BedrockAccount(BedrockAccount.DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCodeConsumer)));
} }
}); });
}); });

View File

@ -17,14 +17,13 @@
*/ */
package net.raphimc.viaproxy.ui.popups; package net.raphimc.viaproxy.ui.popups;
import net.raphimc.mcauth.step.msa.StepMsaDeviceCode; import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
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.GBC; import net.raphimc.viaproxy.util.GBC;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
@ -60,7 +59,7 @@ public class AddAccountPopup extends JDialog {
} }
}); });
this.setTitle(I18n.get("popup.login_account.title")); this.setTitle(I18n.get("popup.login_account.title"));
this.setSize(400, 200); this.setSize(400, 140);
this.setResizable(false); this.setResizable(false);
this.setLocationRelativeTo(this.parent); this.setLocationRelativeTo(this.parent);
} }
@ -72,31 +71,17 @@ public class AddAccountPopup extends JDialog {
JLabel browserLabel = new JLabel("<html><p>" + I18n.get("popup.login_account.instructions.browser") + "</p></html>"); JLabel browserLabel = new JLabel("<html><p>" + I18n.get("popup.login_account.instructions.browser") + "</p></html>");
GBC.create(contentPane).grid(0, 0).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(browserLabel); GBC.create(contentPane).grid(0, 0).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(browserLabel);
JLabel urlLabel = new JLabel("<html><a href=\"\">" + this.deviceCode.verificationUri() + "</a></html>"); JLabel urlLabel = new JLabel("<html><a href=\"\">" + this.deviceCode.getDirectVerificationUri() + "</a></html>");
urlLabel.addMouseListener(new MouseAdapter() { urlLabel.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
AddAccountPopup.this.parent.openURL(AddAccountPopup.this.deviceCode.verificationUri()); AddAccountPopup.this.parent.openURL(AddAccountPopup.this.deviceCode.getDirectVerificationUri());
} }
}); });
GBC.create(contentPane).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(urlLabel); GBC.create(contentPane).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(urlLabel);
JLabel enterCodeLabel = new JLabel("<html><p>" + I18n.get("popup.login_account.instructions.code") + "</p></html>");
GBC.create(contentPane).grid(0, 2).weightx(1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(enterCodeLabel);
JLabel codeLabel = new JLabel(this.deviceCode.userCode());
GBC.create(contentPane).grid(0, 3).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(codeLabel);
JLabel closeInfo = new JLabel("<html><p>" + I18n.get("popup.login_account.instructions.close") + "</p></html>"); JLabel closeInfo = new JLabel("<html><p>" + I18n.get("popup.login_account.instructions.close") + "</p></html>");
GBC.create(contentPane).grid(0, 4).weightx(1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(closeInfo); GBC.create(contentPane).grid(0, 2).weightx(1).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(closeInfo);
}
{
JButton copyCodeButton = new JButton(I18n.get("popup.login_account.instructions.copy_code.label"));
copyCodeButton.addActionListener(event -> {
StringSelection selection = new StringSelection(this.deviceCode.userCode());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
});
GBC.create(contentPane).grid(0, 5).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).fill(GridBagConstraints.HORIZONTAL).add(copyCodeButton);
} }
this.setContentPane(contentPane); this.setContentPane(contentPane);
} }

View File

@ -83,9 +83,7 @@ tab.ui_settings.language.success=Die Sprache wurde zu %s (%s) geändert. ViaProx
popup.login_account.title=Konto hinzufügen popup.login_account.title=Konto hinzufügen
popup.login_account.instructions.browser=Bitte öffne folgende URL in deinem Browser: popup.login_account.instructions.browser=Bitte öffne folgende URL in deinem Browser:
popup.login_account.instructions.code=Gib den folgenden Code ein:
popup.login_account.instructions.close=Das Popup schließt sich automatisch, nachdem du angemeldet wurdest. popup.login_account.instructions.close=Das Popup schließt sich automatisch, nachdem du angemeldet wurdest.
popup.login_account.instructions.copy_code.label=Code kopieren
popup.download.title=Lade herunter... popup.download.title=Lade herunter...

View File

@ -83,9 +83,7 @@ tab.ui_settings.language.success=Language changed to %s (%s). ViaProxy will now
popup.login_account.title=Add Account popup.login_account.title=Add Account
popup.login_account.instructions.browser=Please open the following URL in your browser: popup.login_account.instructions.browser=Please open the following URL in your browser:
popup.login_account.instructions.code=Enter the following code:
popup.login_account.instructions.close=The popup will close automatically after you have been logged in. popup.login_account.instructions.close=The popup will close automatically after you have been logged in.
popup.login_account.instructions.copy_code.label=Copy code
popup.download.title=Downloading... popup.download.title=Downloading...

View File

@ -83,9 +83,7 @@ tab.ui_settings.language.success=语言已更改为%s%s。ViaProxy即将
popup.login_account.title=添加账户 popup.login_account.title=添加账户
popup.login_account.instructions.browser=请在浏览器中打开以下URL popup.login_account.instructions.browser=请在浏览器中打开以下URL
popup.login_account.instructions.code=输入以下代码:
popup.login_account.instructions.close=登录后,弹窗将自动关闭。 popup.login_account.instructions.close=登录后,弹窗将自动关闭。
popup.login_account.instructions.copy_code.label=复制代码
popup.download.title=正在下载... popup.download.title=正在下载...