From 577277d95b0e634c0988989bffcb2527f5cfde4f Mon Sep 17 00:00:00 2001
From: winterflyt <36+winterflyt@noreply.skidsolutions.xyz>
Date: Mon, 30 Nov 2026 05:46:24 +0200
Subject: [PATCH] Upload files to "src/openonyx/connection/internal"
---
.../connection/internal/AuthException.java | 11 +
.../connection/internal/AuthHttpClient.java | 205 +++++++++++
.../internal/AuthHttpClientData.java | 26 ++
.../internal/MicrosoftLoginServer.java | 205 +++++++++++
.../connection/internal/XboxLiveAuth.java | 321 ++++++++++++++++++
5 files changed, 768 insertions(+)
create mode 100644 src/openonyx/connection/internal/AuthException.java
create mode 100644 src/openonyx/connection/internal/AuthHttpClient.java
create mode 100644 src/openonyx/connection/internal/AuthHttpClientData.java
create mode 100644 src/openonyx/connection/internal/MicrosoftLoginServer.java
create mode 100644 src/openonyx/connection/internal/XboxLiveAuth.java
diff --git a/src/openonyx/connection/internal/AuthException.java b/src/openonyx/connection/internal/AuthException.java
new file mode 100644
index 0000000..0f7e366
--- /dev/null
+++ b/src/openonyx/connection/internal/AuthException.java
@@ -0,0 +1,11 @@
+package openonyx.connection.internal;
+
+public class AuthException extends Exception {
+ public AuthException(String string) {
+ super(string);
+ }
+
+ public AuthException(String string, Throwable throwable) {
+ super(string, throwable);
+ }
+}
diff --git a/src/openonyx/connection/internal/AuthHttpClient.java b/src/openonyx/connection/internal/AuthHttpClient.java
new file mode 100644
index 0000000..c49846d
--- /dev/null
+++ b/src/openonyx/connection/internal/AuthHttpClient.java
@@ -0,0 +1,205 @@
+package openonyx.connection.internal;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.net.Proxy.Type;
+import java.nio.charset.StandardCharsets;
+import openonyx.core.OnyxClient;
+
+public final class AuthHttpClient {
+ private static final int H = 20000;
+ private static final String e = "okhttp/4.12.0";
+
+ public static AuthHttpClientData L(String string, int i) throws AuthException {
+ Proxy proxy = OnyxClient.accountManager.getProxySettings().L();
+ String[] strings = new String[0];
+ boolean bl = true;
+ return L(string, "GET", null, i, proxy, strings);
+ }
+
+ public static String L(String string) {
+ return URLEncoder.encode(string, StandardCharsets.UTF_8);
+ }
+
+ public static AuthHttpClientData L(String string, String... strings) throws AuthException {
+ return L(string, 20000, strings);
+ }
+
+ // $VF: Could not inline inconsistent finally blocks
+ // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
+ private static AuthHttpClientData L(String string, String string1, String string2, int i, Proxy proxy, String... strings) throws AuthException {
+ HttpURLConnection httpURLConnection;
+ try {
+ httpURLConnection = (HttpURLConnection)new URL(string).openConnection(proxy);
+ } catch (IOException | ClassCastException iOException) {
+ throw new AuthException("Invalid request URL", iOException);
+ }
+
+ HttpURLConnection httpURLConnection1 = httpURLConnection;
+
+ try {
+ try {
+ httpURLConnection1.setConnectTimeout(i);
+ byte d = 0;
+ httpURLConnection.setReadTimeout(i);
+ httpURLConnection.setInstanceFollowRedirects(false);
+ httpURLConnection.setRequestMethod(string1);
+ httpURLConnection.setRequestProperty("User-Agent", "okhttp/4.12.0");
+
+ for (byte b = 0; d + 1 < strings.length; d = b) {
+ String string5 = strings[b];
+ int k = b + 1;
+ b += 2;
+ httpURLConnection.setRequestProperty(string5, strings[k]);
+ }
+
+ label160: {
+ if (string2 != null) {
+ byte[] c;
+ byte[] ex = c = string2.getBytes(StandardCharsets.UTF_8);
+ httpURLConnection.setDoOutput(true);
+ httpURLConnection.setFixedLengthStreamingMode(ex.length);
+ OutputStream outputStream = httpURLConnection.getOutputStream();
+
+ try {
+ outputStream.write(c);
+ } catch (Throwable throwable3) {
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (Throwable throwable2) {
+ throwable3.addSuppressed(throwable2);
+ throw throwable3;
+ }
+
+ throw throwable3;
+ }
+
+ throw throwable3;
+ }
+
+ if (outputStream != null) {
+ httpURLConnection1 = httpURLConnection;
+ outputStream.close();
+ break label160;
+ }
+ }
+
+ httpURLConnection1 = httpURLConnection;
+ }
+
+ int j;
+ InputStream inputStream = (j = httpURLConnection1.getResponseCode()) >= 400
+ ? httpURLConnection.getErrorStream()
+ : httpURLConnection.getInputStream();
+ String string4 = "";
+ if (inputStream != null) {
+ InputStream inputStream1 = inputStream;
+
+ try {
+ string4 = new String(inputStream1.readAllBytes(), StandardCharsets.UTF_8);
+ } catch (Throwable throwable1) {
+ if (inputStream1 != null) {
+ try {
+ inputStream1.close();
+ } catch (Throwable throwable) {
+ throwable1.addSuppressed(throwable);
+ throw throwable1;
+ }
+
+ throw throwable1;
+ }
+
+ throw throwable1;
+ }
+
+ if (inputStream1 != null) {
+ inputStream1.close();
+ }
+ }
+
+ authHttpClientData = new AuthHttpClientData(j, string4);
+ } catch (IOException iOException1) {
+ string1 = proxy.type() == Type.DIRECT ? null : OnyxClient.accountManager.getProxySettings().d();
+ String string3 = string1 != null && !string1.isBlank() ? string1 : iOException1.getMessage();
+ throw new AuthException(new StringBuilder().insert(0, "Network error: ").append(string3).toString(), iOException1);
+ }
+ } catch (Throwable throwable4) {
+ httpURLConnection.disconnect();
+ throw throwable4;
+ }
+
+ httpURLConnection.disconnect();
+ return authHttpClientData;
+ }
+
+ public static String L(JsonObject jsonObject, String string) {
+ JsonElement jsonElement;
+ return (jsonElement = jsonObject.get(string)) != null && jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()
+ ? jsonElement.getAsString()
+ : null;
+ }
+
+ public static AuthHttpClientData L(String string, String string1) throws AuthException {
+ Proxy proxy = L();
+ String[] strings = new String[2];
+ boolean bl = true;
+ strings[0] = "Content-Type";
+ strings[1] = "application/x-www-form-urlencoded";
+ return L(string, "POST", string1, 20000, proxy, strings);
+ }
+
+ public static JsonObject L(JsonObject jsonObject) {
+ JsonObject jsonObject1 = jsonObject;
+ JsonElement jsonElement;
+ if ((jsonElement = jsonObject1.get("DisplayClaims")) != null && jsonElement.isJsonObject()) {
+ if ((jsonElement = jsonElement.getAsJsonObject().get("xui")) != null && jsonElement.isJsonArray()) {
+ JsonArray jsonArray;
+ return (jsonArray = jsonElement.getAsJsonArray()).size() != 0 && jsonArray.get(0).isJsonObject() ? jsonArray.get(0).getAsJsonObject() : null;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ public static AuthHttpClientData L(String string, String string1, String... strings) throws AuthException {
+ String string2 = string;
+ String[] strings2 = new String[strings.length + 4];
+ boolean bl = true;
+ String[] strings1 = strings2;
+ strings1[0] = "Content-Type";
+ strings1[1] = "application/json";
+ strings1[2] = "Accept";
+ strings1[3] = "application/json";
+ System.arraycopy(strings, 0, strings1, 4, strings.length);
+ return L(string2, "POST", string1, 20000, L(), strings1);
+ }
+
+ public static AuthHttpClientData L(String string, int i, String... strings) throws AuthException {
+ return L(string, "GET", null, i, L(), strings);
+ }
+
+ private AuthHttpClient() {
+ }
+
+ private static Proxy L() {
+ return OnyxClient.accountManager.d();
+ }
+
+ public static long L(JsonObject jsonObject, String string, long l) {
+ JsonElement jsonElement;
+ return (jsonElement = jsonObject.get(string)) != null && jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()
+ ? jsonElement.getAsLong()
+ : l;
+ }
+}
diff --git a/src/openonyx/connection/internal/AuthHttpClientData.java b/src/openonyx/connection/internal/AuthHttpClientData.java
new file mode 100644
index 0000000..07293a6
--- /dev/null
+++ b/src/openonyx/connection/internal/AuthHttpClientData.java
@@ -0,0 +1,26 @@
+package openonyx.connection.internal;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+public record AuthHttpClientData(int status, String body) {
+ public JsonObject L() throws AuthException {
+ AuthHttpClientData authHttpClientData1 = this;
+
+ try {
+ JsonElement jsonElement;
+ if ((jsonElement = new JsonParser().parse(authHttpClientData1.body)) != null && jsonElement.isJsonObject()) {
+ return jsonElement.getAsJsonObject();
+ } else {
+ throw new AuthException("Malformed response from the server");
+ }
+ } catch (RuntimeException runtimeException) {
+ throw new AuthException("Malformed response from the server", runtimeException);
+ }
+ }
+
+ public boolean L() {
+ return this.status >= 200 && this.status < 300;
+ }
+}
diff --git a/src/openonyx/connection/internal/MicrosoftLoginServer.java b/src/openonyx/connection/internal/MicrosoftLoginServer.java
new file mode 100644
index 0000000..d07e8b7
--- /dev/null
+++ b/src/openonyx/connection/internal/MicrosoftLoginServer.java
@@ -0,0 +1,205 @@
+package openonyx.connection.internal;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpServer;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.BindException;
+import java.net.InetSocketAddress;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Consumer;
+import openonyx.core.MinecraftAccess;
+import openonyx.core.OnyxClient;
+import openonyx.utilities.AsyncExecutor;
+import openonyx.utilities.FileUtils;
+
+public final class MicrosoftLoginServer implements MinecraftAccess {
+ private static final int M = 1337;
+ private final String L;
+ private static final String j = "
%s\n\n%s
\n
You can close this tab and return to Minecraft.
";
+ private final Consumer xboxLiveAuthData2Consumer;
+ private static final String h = "127.0.0.1";
+ private static final String l = "/";
+ private static MicrosoftLoginServer INSTANCE;
+ private final HttpServer httpServer;
+ private final String i;
+ private final Consumer stringConsumer;
+ private static final int H = 300;
+ private final AtomicBoolean atomicBoolean = new AtomicBoolean();
+
+ public static synchronized MicrosoftLoginServer L(Consumer consumer, Consumer consumer1) throws AuthException {
+ Consumer consumer2 = consumer;
+ if (!XboxLiveAuth.L()) {
+ throw new AuthException("No Azure client id configured — set MicrosoftAuth.CLIENT_ID");
+ }
+
+ i();
+
+ HttpServer httpServerx;
+ try {
+ httpServerx = HttpServer.create(new InetSocketAddress("127.0.0.1", 1337), 0);
+ } catch (BindException bindException) {
+ throw new AuthException("Microsoft sign-in requires local port 1337 to be available", bindException);
+ } catch (IOException iOException) {
+ throw new AuthException("Could not open the local login server", iOException);
+ }
+
+ MicrosoftLoginServer microsoftLoginServer = new MicrosoftLoginServer(httpServerx, 1337, consumer2, consumer1);
+ httpServerx.createContext("/", httpExchange -> {
+ MicrosoftLoginServer microsoftLoginServer2 = this;
+ Map map;
+ String string = (String)(map = L(httpExchange.getRequestURI().getRawQuery())).get("code");
+ String string1 = map.get("error_description") != null ? (String)map.get("error_description") : (String)map.get("error");
+ if (string == null) {
+ microsoftLoginServer2.L(httpExchange, "Sign-in failed");
+ microsoftLoginServer2.L(string1 != null ? string1 : "Microsoft did not return an authorization code");
+ } else if (microsoftLoginServer2.atomicBoolean.compareAndSet(false, true)) {
+ try {
+ xboxLiveAuthData2 = XboxLiveAuth.L(string, microsoftLoginServer2.L);
+ } catch (AuthException authException) {
+ OnyxClient.LOGGER.warn("Microsoft sign-in failed", authException);
+ microsoftLoginServer2.L(httpExchange, "Sign-in failed");
+ microsoftLoginServer2.L();
+ mc.addScheduledTask(() -> this.stringConsumer.accept(authException.getMessage()));
+ return;
+ }
+
+ microsoftLoginServer2.L(httpExchange, "Signed in");
+ microsoftLoginServer2.L();
+ mc.addScheduledTask(() -> this.xboxLiveAuthData2Consumer.accept(xboxLiveAuthData2));
+ }
+ });
+ httpServerx.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
+ httpServerx.start();
+ INSTANCE = microsoftLoginServer;
+ AsyncExecutor.L(() -> {
+ try {
+ Thread.sleep(300000L);
+ } catch (InterruptedException interruptedException) {
+ Thread.currentThread().interrupt();
+ return;
+ }
+
+ microsoftLoginServer.L("Sign-in timed out");
+ });
+ return microsoftLoginServer;
+ }
+
+ public String d() {
+ return this.i;
+ }
+
+ private void L(HttpExchange httpExchange, String string) {
+ Object[] objects = new Object[2];
+ boolean bl = true;
+ objects[0] = string;
+ objects[1] = string;
+ byte[] b = "%s\n\n%s
\n
You can close this tab and return to Minecraft.
"
+ .formatted(objects)
+ .getBytes(StandardCharsets.UTF_8);
+
+ try {
+ OutputStream outputStream = httpExchange.getResponseBody();
+
+ try {
+ httpExchange.getResponseHeaders().add("Content-Type", "text/html; charset=utf-8");
+ httpExchange.sendResponseHeaders(200, b.length);
+ outputStream.write(b);
+ } catch (Throwable throwable1) {
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (Throwable throwable) {
+ throwable1.addSuppressed(throwable);
+ throw throwable1;
+ }
+
+ throw throwable1;
+ }
+
+ throw throwable1;
+ }
+
+ if (outputStream != null) {
+ outputStream.close();
+ return;
+ }
+ } catch (IOException iOException) {
+ OnyxClient.LOGGER.warn("Failed to answer the OAuth callback", iOException);
+ }
+ }
+
+ public static synchronized void i() {
+ if (INSTANCE != null) {
+ INSTANCE.D();
+ }
+ }
+
+ public String L() {
+ return this.L;
+ }
+
+ public void D() {
+ if (this.atomicBoolean.compareAndSet(false, true)) {
+ this.L();
+ }
+ }
+
+ public void d() {
+ FileUtils.L(this.i);
+ }
+
+ private MicrosoftLoginServer(HttpServer httpServer, int i, Consumer consumer, Consumer consumer1) {
+ this.httpServer = httpServerx;
+ this.xboxLiveAuthData2Consumer = consumer;
+ this.stringConsumer = consumer1;
+ this.L = new StringBuilder().insert(0, "http://127.0.0.1:").append(ix).append("/").toString();
+ this.i = XboxLiveAuth.L(this.L);
+ }
+
+ private static Map L(String string) {
+ String string1 = string;
+ HashMap hashMap = new HashMap();
+ if (string1 != null && !string1.isEmpty()) {
+ String[] strings;
+ int k = (strings = string1.split("&")).length;
+
+ int jx;
+ for (int lx = jx = 0; lx < k; lx = ++jx) {
+ int ix;
+ String string2;
+ if ((ix = (string2 = strings[jx]).indexOf(61)) > 0) {
+ hashMap.put(
+ URLDecoder.decode(string2.substring(0, ix), StandardCharsets.UTF_8), URLDecoder.decode(string2.substring(ix + 1), StandardCharsets.UTF_8)
+ );
+ }
+ }
+
+ return hashMap;
+ } else {
+ return hashMap;
+ }
+ }
+
+ private void L() {
+ MicrosoftLoginServer microsoftLoginServer1 = this;
+ microsoftLoginServer1.httpServer.stop(0);
+ synchronized (MicrosoftLoginServer.class) {
+ if (INSTANCE == microsoftLoginServer1) {
+ INSTANCE = null;
+ }
+ }
+ }
+
+ private void L(String string) {
+ if (this.atomicBoolean.compareAndSet(false, true)) {
+ this.L();
+ mc.addScheduledTask(() -> this.stringConsumer.accept(string));
+ }
+ }
+}
diff --git a/src/openonyx/connection/internal/XboxLiveAuth.java b/src/openonyx/connection/internal/XboxLiveAuth.java
new file mode 100644
index 0000000..966c2b1
--- /dev/null
+++ b/src/openonyx/connection/internal/XboxLiveAuth.java
@@ -0,0 +1,321 @@
+package openonyx.connection.internal;
+
+import com.google.gson.JsonObject;
+import java.util.UUID;
+import openonyx.core.OnyxClient;
+import org.apache.logging.log4j.Logger;
+
+public final class XboxLiveAuth {
+ private static final long c = 2148916238L;
+ private static final int a = 401;
+ private static final String k = "{\"Properties\":{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\"%s\"]},\"RelyingParty\":\"rp://api.minecraftservices.com/\",\"TokenType\":\"JWT\"}";
+ private static final String g = "{\"Properties\":{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\"%s\"},\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\"}";
+ private static final String M = "https://user.auth.xboxlive.com/user/authenticate";
+ private static final long L = 2148916235L;
+ private static final int j = 403;
+ private static final String m = "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize";
+ public static final String h = "c36a9fb6-4f2a-41ff-90bd-ae7cc92031eb";
+ private static final long l = 2148916233L;
+ private static final String I = "{\"identityToken\":\"XBL3.0 x=%s;%s\"}";
+ private static final int d = 500;
+ private static final String i = "https://api.minecraftservices.com/minecraft/profile";
+ private static final int f = 429;
+ private static final String H = "https://xsts.auth.xboxlive.com/xsts/authorize";
+ private static final String e = "https://api.minecraftservices.com/authentication/login_with_xbox";
+
+ private XboxLiveAuth() {
+ }
+
+ private static AuthException d(AuthHttpClientData authHttpClientData) {
+ long lx;
+ long mx;
+ label24: {
+ try {
+ lx = AuthHttpClient.L(authHttpClientData.L(), "XErr", 0L);
+ } catch (AuthException authException) {
+ mx = lx = 0L;
+ break label24;
+ }
+
+ mx = lx;
+ }
+
+ if (mx == 2148916233L) {
+ return new AuthException("This Microsoft account has no Xbox profile");
+ } else if (lx == 2148916235L) {
+ return new AuthException("Xbox Live is unavailable in this region");
+ } else {
+ return lx == 2148916238L
+ ? new AuthException("Child account — must be added to a Microsoft family")
+ : new AuthException(new StringBuilder().insert(0, "Xbox Live security check failed (").append(authHttpClientData.status()).append(")").toString());
+ }
+ }
+
+ public static boolean L() {
+ return XboxLiveAuthMode.AZURE.L();
+ }
+
+ public static XboxLiveAuthData2 L(String string, String string1) throws AuthException {
+ L(XboxLiveAuthMode.AZURE);
+ return L(
+ new StringBuilder()
+ .insert(0, "client_id=")
+ .append(AuthHttpClient.L(XboxLiveAuthMode.AZURE.I()))
+ .append("&redirect_uri=")
+ .append(AuthHttpClient.L(string1))
+ .append("&scope=")
+ .append(AuthHttpClient.L(XboxLiveAuthMode.AZURE.h()))
+ .append("&grant_type=authorization_code&code=")
+ .append(AuthHttpClient.L(string))
+ .toString(),
+ XboxLiveAuthMode.AZURE
+ );
+ }
+
+ public static XboxLiveAuthData2 d(String string, XboxLiveAuthMode xboxLiveAuthMode) throws AuthException {
+ L(xboxLiveAuthMode);
+ if (string != null && !string.isBlank()) {
+ String string1 = string.replaceAll("\\s", "");
+ String string2 = new StringBuilder()
+ .insert(0, "client_id=")
+ .append(AuthHttpClient.L(xboxLiveAuthMode.I()))
+ .append("&grant_type=refresh_token")
+ .toString();
+ if (xboxLiveAuthMode.d() != null) {
+ string2 = new StringBuilder().insert(0, string2).append("&redirect_uri=").append(AuthHttpClient.L(xboxLiveAuthMode.d())).toString();
+ }
+
+ return L(
+ new StringBuilder()
+ .insert(0, string2)
+ .append("&refresh_token=")
+ .append(AuthHttpClient.L(string1))
+ .append("&scope=")
+ .append(AuthHttpClient.L(xboxLiveAuthMode.h()))
+ .toString(),
+ xboxLiveAuthMode
+ );
+ } else {
+ throw new AuthException("No refresh token stored for this account");
+ }
+ }
+
+ private static AuthException L(AuthHttpClientData authHttpClientData) {
+ AuthHttpClientData authHttpClientData1 = authHttpClientData;
+ Logger logger = OnyxClient.LOGGER;
+ Object[] objects = new Object[2];
+ boolean bl = true;
+ objects[0] = authHttpClientData1.status();
+ objects[1] = authHttpClientData1.body();
+ logger.error("Microsoft token endpoint returned {}: {}", objects);
+ if (authHttpClientData1.status() == 429) {
+ return new AuthException("You are rate limited, try again in a moment");
+ }
+
+ if (authHttpClientData1.status() >= 500) {
+ return new AuthException("Microsoft services are unavailable");
+ }
+
+ try {
+ JsonObject jsonObject = authHttpClientData1.L();
+ String string = AuthHttpClient.L(jsonObject, "error_description");
+ String string1 = AuthHttpClient.L(jsonObject, "error");
+ string2 = string != null ? string : string1;
+ } catch (AuthException authException) {
+ Object object;
+ return (object = null) == null
+ ? new AuthException(new StringBuilder().insert(0, "Microsoft rejected the login (").append(authHttpClientData1.status()).append(")").toString())
+ : new AuthException(object.replaceAll("\\s+", " ").trim());
+ }
+
+ return string2 == null
+ ? new AuthException(new StringBuilder().insert(0, "Microsoft rejected the login (").append(authHttpClientData1.status()).append(")").toString())
+ : new AuthException(string2.replaceAll("\\s+", " ").trim());
+ }
+
+ private static XboxLiveAuthData2 L(String string, String string1, XboxLiveAuthMode xboxLiveAuthMode) throws AuthException {
+ String string2 = string;
+ String[] strings1 = new Object[1];
+ boolean bl1 = true;
+ boolean bl2 = false;
+ strings1[0] = xboxLiveAuthMode.D() + string2;
+ String string7 = "{\"Properties\":{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\"%s\"},\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\"}"
+ .formatted(strings1);
+ strings1 = new String[0];
+ bl1 = true;
+ AuthHttpClientData authHttpClientData;
+ if (!(authHttpClientData = AuthHttpClient.L("https://user.auth.xboxlive.com/user/authenticate", string7, strings1)).L()) {
+ throw new AuthException(new StringBuilder().insert(0, "Xbox Live rejected the login (").append(authHttpClientData.status()).append(")").toString());
+ }
+
+ JsonObject jsonObject4 = authHttpClientData.L();
+ string = AuthHttpClient.L(jsonObject4, "Token");
+ JsonObject jsonObject = AuthHttpClient.L(jsonObject4);
+ if (string != null && jsonObject != null) {
+ String string5;
+ if ((string5 = AuthHttpClient.L(jsonObject, "uhs")) == null) {
+ throw new AuthException("Xbox Live returned no user hash");
+ } else {
+ strings1 = new Object[1];
+ bl1 = true;
+ strings1[0] = string;
+ string7 = "{\"Properties\":{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\"%s\"]},\"RelyingParty\":\"rp://api.minecraftservices.com/\",\"TokenType\":\"JWT\"}"
+ .formatted(strings1);
+ strings1 = new String[0];
+ bl1 = true;
+ AuthHttpClientData authHttpClientData1;
+ if (!(authHttpClientData1 = AuthHttpClient.L("https://xsts.auth.xboxlive.com/xsts/authorize", string7, strings1)).L()) {
+ throw d(authHttpClientData1);
+ } else {
+ String string3;
+ JsonObject jsonObject1;
+ if ((string3 = AuthHttpClient.L(jsonObject1 = authHttpClientData1.L(), "Token")) == null) {
+ throw new AuthException("Xbox Live returned no security token");
+ } else {
+ JsonObject jsonObject2;
+ String string4 = (jsonObject2 = AuthHttpClient.L(jsonObject1)) == null ? null : AuthHttpClient.L(jsonObject2, "xid");
+ strings1 = new Object[2];
+ bl1 = true;
+ strings1[0] = string5;
+ strings1[1] = string3;
+ string7 = "{\"identityToken\":\"XBL3.0 x=%s;%s\"}".formatted(strings1);
+ strings1 = new String[0];
+ bl1 = true;
+ AuthHttpClientData authHttpClientData2;
+ if ((authHttpClientData2 = AuthHttpClient.L("https://api.minecraftservices.com/authentication/login_with_xbox", string7, strings1)).status()
+ == 403) {
+ throw new AuthException("This build's Azure app is not approved for the Minecraft API");
+ } else if (!authHttpClientData2.L()) {
+ throw new AuthException(
+ new StringBuilder().insert(0, "Minecraft services rejected the login (").append(authHttpClientData2.status()).append(")").toString()
+ );
+ } else {
+ JsonObject jsonObject3;
+ String string6;
+ if ((string6 = AuthHttpClient.L(jsonObject3 = authHttpClientData2.L(), "access_token")) == null) {
+ throw new AuthException("Minecraft services returned no access token");
+ } else {
+ long lx = System.currentTimeMillis() + AuthHttpClient.L(jsonObject3, "expires_in", 86400L) * 1000L;
+ String[] strings = new String[4];
+ boolean bl = true;
+ strings[0] = "Authorization";
+ strings[1] = new StringBuilder().insert(0, "Bearer ").append(string6).toString();
+ strings[2] = "Accept";
+ strings[3] = "application/json";
+ AuthHttpClientData authHttpClientData3;
+ if (!(authHttpClientData3 = AuthHttpClient.L("https://api.minecraftservices.com/minecraft/profile", strings)).L()) {
+ throw new AuthException("This account does not own Minecraft");
+ } else {
+ jsonObject4 = authHttpClientData3.L();
+ string = AuthHttpClient.L(jsonObject4, "name");
+ string3 = AuthHttpClient.L(jsonObject4, "id");
+ if (string != null && string3 != null) {
+ return new XboxLiveAuthData2(xboxLiveAuthMode, string1, string6, lx, L(string3), string, string4);
+ } else {
+ throw new AuthException("Minecraft returned an incomplete profile");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ throw new AuthException("Xbox Live returned no token");
+ }
+ }
+
+ private static XboxLiveAuthData2 L(String string, XboxLiveAuthMode xboxLiveAuthMode) throws AuthException {
+ String string1 = string;
+ AuthHttpClientData authHttpClientData;
+ if (!(authHttpClientData = AuthHttpClient.L(xboxLiveAuthMode.L(), string1)).L()) {
+ throw L(authHttpClientData);
+ } else {
+ JsonObject jsonObject = authHttpClientData.L();
+ string = AuthHttpClient.L(jsonObject, "access_token");
+ String string2 = AuthHttpClient.L(jsonObject, "refresh_token");
+ if (string == null) {
+ throw new AuthException("Microsoft did not return an access token");
+ } else if (string2 == null) {
+ throw new AuthException("Microsoft did not return a refresh token");
+ } else {
+ return L(string, string2, xboxLiveAuthMode);
+ }
+ }
+ }
+
+ private static void L(XboxLiveAuthMode xboxLiveAuthMode) throws AuthException {
+ if (!xboxLiveAuthMode.L()) {
+ throw new AuthException("No Azure client id configured — set MicrosoftAuth.CLIENT_ID");
+ }
+ }
+
+ public static XboxLiveAuthData L(String string) throws AuthException {
+ String string1 = string;
+ if (string1 != null && !string1.isBlank()) {
+ String[] strings = new String[4];
+ boolean bl = true;
+ strings[0] = "Authorization";
+ boolean bl1 = true;
+ strings[1] = "Bearer " + string1.trim();
+ strings[2] = "Accept";
+ strings[3] = "application/json";
+ AuthHttpClientData authHttpClientData;
+ if ((authHttpClientData = AuthHttpClient.L("https://api.minecraftservices.com/minecraft/profile", strings)).status() == 401) {
+ throw new AuthException("Access token is invalid or expired");
+ } else if (!authHttpClientData.L()) {
+ throw new AuthException(
+ new StringBuilder().insert(0, "Minecraft services rejected the token (").append(authHttpClientData.status()).append(")").toString()
+ );
+ } else {
+ JsonObject jsonObject = authHttpClientData.L();
+ string = AuthHttpClient.L(jsonObject, "name");
+ String string2 = AuthHttpClient.L(jsonObject, "id");
+ if (string != null && string2 != null) {
+ return new XboxLiveAuthData(L(string2), string);
+ } else {
+ throw new AuthException("Minecraft returned an incomplete profile");
+ }
+ }
+ } else {
+ throw new AuthException("No access token provided");
+ }
+ }
+
+ public static UUID L(String string) throws AuthException {
+ String string1 = string;
+ if ((string = string1.replace("-", "").trim()).length() != 32) {
+ throw new AuthException("Malformed profile id");
+ }
+
+ try {
+ return UUID.fromString(
+ new StringBuilder()
+ .insert(0, string.substring(0, 8))
+ .append("-")
+ .append(string.substring(8, 12))
+ .append("-")
+ .append(string.substring(12, 16))
+ .append("-")
+ .append(string.substring(16, 20))
+ .append("-")
+ .append(string.substring(20))
+ .toString()
+ );
+ } catch (IllegalArgumentException illegalArgumentException) {
+ throw new AuthException("Malformed profile id", illegalArgumentException);
+ }
+ }
+
+ public static String L(String string) {
+ return new StringBuilder()
+ .insert(0, "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=")
+ .append(AuthHttpClient.L(XboxLiveAuthMode.AZURE.I()))
+ .append("&redirect_uri=")
+ .append(AuthHttpClient.L(string))
+ .append("&response_type=code&display=touch&scope=")
+ .append(AuthHttpClient.L(XboxLiveAuthMode.AZURE.h()))
+ .append("&prompt=select_account")
+ .toString();
+ }
+}