Skip to content

Commit

Permalink
Use /profiles/minecraft instead of /users/profiles/minecraft
Browse files Browse the repository at this point in the history
The authlib-injector spect does not require /users/profiles/minecraft to
be implemented, so we should POST to /profiles/minecraft to get player
UUIDs.
  • Loading branch information
evan-goode committed Aug 18, 2024
1 parent 5f747af commit b6d0725
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static URLConnection openConnection(URL address, Proxy proxy) throws IOEx
String accessToken = sessionId.split(":")[1];

String uuid = null;
uuid = MojangApi.getUuid(user);
uuid = MojangApi.getUuid(user, proxy);
if (uuid == null) {
return new ByteArrayUrlConnection(("Couldn't find UUID of " + user).getBytes("utf-8"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static URLConnection openConnection(URL address, Proxy proxy) throws IOException
if (capeOwner != null) {
// since we do not need to process the image, open a direct connection bypassing
// Handler
Texture texture = MojangApi.getTexture(MojangApi.getUuid(capeOwner), "CAPE");
Texture texture = MojangApi.getTexture(MojangApi.getUuid(capeOwner, proxy), "CAPE");
if (texture == null)
return null;

Expand All @@ -91,7 +91,7 @@ static URLConnection openConnection(URL address, 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)
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,36 @@
import org.prismlauncher.legacy.utils.Base64;
import org.prismlauncher.legacy.utils.api.ApiServers;
import org.prismlauncher.legacy.utils.json.JsonParser;
import org.prismlauncher.legacy.utils.url.UrlUtils;

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.util.List;
import java.util.Map;

/**
* Basic wrapper for Mojang's Minecraft API.
*/
@SuppressWarnings("unchecked")
public final class MojangApi {
public static String getUuid(String username) throws IOException {
try (InputStream in = new URL(ApiServers.getAccountURL() + "/users/profiles/minecraft/" + username).openStream()) {
Map<String, Object> map = (Map<String, Object>) JsonParser.parse(in);
return (String) map.get("id");
public static String getUuid(String username, Proxy proxy) throws IOException {
URL url = new URL(ApiServers.getAccountURL() + "/profiles/minecraft");
HttpURLConnection connection = (HttpURLConnection) UrlUtils.openConnection(url, proxy);
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");
}
}

Expand Down

0 comments on commit b6d0725

Please sign in to comment.