Use /profiles/minecraft instead of /users/profiles/minecraft

The authlib-injector spect does not require /users/profiles/minecraft to
be implemented, so we should POST to /profiles/minecraft to get player
UUIDs.
This commit is contained in:
Evan Goode 2024-08-18 00:12:38 -04:00
parent 5f747af9db
commit 30f19a655a
3 changed files with 23 additions and 8 deletions

View File

@ -79,12 +79,12 @@ public final class OnlineModeFix {
throw new AssertionError("missing sessionId"); throw new AssertionError("missing sessionId");
} }
// sessionId hashas the form: // sessionId has the form:
// token:<accessToken>:<player UUID> // token:<accessToken>:<player UUID>
String accessToken = sessionId.split(":")[1]; String accessToken = sessionId.split(":")[1];
String uuid = null; String uuid = null;
uuid = MojangApi.getUuid(user); uuid = MojangApi.getUuid(user, proxy);
if (uuid == null) { if (uuid == null) {
return new ByteArrayUrlConnection(("Couldn't find UUID of " + user).getBytes("utf-8")); return new ByteArrayUrlConnection(("Couldn't find UUID of " + user).getBytes("utf-8"));
} }

View File

@ -80,7 +80,7 @@ final class SkinFix {
if (capeOwner != null) { if (capeOwner != null) {
// since we do not need to process the image, open a direct connection bypassing // since we do not need to process the image, open a direct connection bypassing
// Handler // Handler
Texture texture = MojangApi.getTexture(MojangApi.getUuid(capeOwner), "CAPE"); Texture texture = MojangApi.getTexture(MojangApi.getUuid(capeOwner, proxy), "CAPE");
if (texture == null) if (texture == null)
return null; return null;
@ -91,7 +91,7 @@ final class SkinFix {
} }
private static URLConnection getSkinConnection(String owner, Proxy proxy) throws IOException { private static URLConnection getSkinConnection(String owner, Proxy proxy) throws IOException {
Texture texture = MojangApi.getTexture(MojangApi.getUuid(owner), "SKIN"); Texture texture = MojangApi.getTexture(MojangApi.getUuid(owner, proxy), "SKIN");
if (texture == null) if (texture == null)
return null; return null;

View File

@ -38,10 +38,15 @@ package org.prismlauncher.legacy.utils.api;
import org.prismlauncher.legacy.utils.Base64; import org.prismlauncher.legacy.utils.Base64;
import org.prismlauncher.legacy.utils.api.ApiServers; import org.prismlauncher.legacy.utils.api.ApiServers;
import org.prismlauncher.legacy.utils.json.JsonParser; import org.prismlauncher.legacy.utils.json.JsonParser;
import org.prismlauncher.legacy.utils.url.UrlUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -49,10 +54,20 @@ import java.util.Map;
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final class MojangApi { public final class MojangApi {
public static String getUuid(String username) throws IOException { public static String getUuid(String username, Proxy proxy) throws IOException {
try (InputStream in = new URL(ApiServers.getAccountURL() + "/users/profiles/minecraft/" + username).openStream()) { URL url = new URL(ApiServers.getAccountURL() + "/profiles/minecraft");
Map<String, Object> map = (Map<String, Object>) JsonParser.parse(in); HttpURLConnection connection = (HttpURLConnection) UrlUtils.openConnection(url, proxy);
return (String) map.get("id"); connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
try (OutputStream os = connection.getOutputStream()) {
String payload = "[\"" + username + "\"]";
os.write(payload.getBytes("utf-8"));
}
try (InputStream in = connection.getInputStream()) {
List<Map<String, Object>> list = (List<Map<String, Object>>) JsonParser.parse(in);
return (String) list.get(0).get("id");
} }
} }