use of org.to2mbn.authlibinjector.internal.org.json.JSONObject in project authlib-injector by to2mbn.
the class YggdrasilConfiguration method parse.
public static YggdrasilConfiguration parse(String apiRoot, String metadataResponse) throws IOException {
if (!apiRoot.endsWith("/"))
apiRoot += "/";
try {
JSONObject response = new JSONObject(metadataResponse);
List<String> skinDomains = new ArrayList<>();
ofNullable(response.optJSONArray("skinDomains")).ifPresent(it -> it.forEach(domain -> {
if (domain instanceof String)
skinDomains.add((String) domain);
}));
Optional<PublicKey> decodedPublickey;
String publickeyString = response.optString("signaturePublickey");
if (publickeyString == null) {
decodedPublickey = empty();
} else {
try {
decodedPublickey = of(loadX509PublicKey(decodePublicKey(publickeyString)));
} catch (IllegalArgumentException | GeneralSecurityException e) {
throw new IOException("Bad signature publickey", e);
}
}
Map<String, String> meta = new TreeMap<>();
ofNullable(response.optJSONObject("meta")).map(JSONObject::toMap).ifPresent(it -> it.forEach((k, v) -> meta.put(k, String.valueOf(v))));
return new YggdrasilConfiguration(apiRoot, unmodifiableList(skinDomains), unmodifiableMap(meta), decodedPublickey);
} catch (JSONException e) {
throw new IOException("Invalid json", e);
}
}
use of org.to2mbn.authlibinjector.internal.org.json.JSONObject in project authlib-injector by to2mbn.
the class DeprecatedApiHttpd method queryCharacterProperty.
private Optional<String> queryCharacterProperty(String uuid, String property) throws UncheckedIOException, JSONException {
String responseText;
try {
responseText = asString(getURL(configuration.getApiRoot() + "sessionserver/session/minecraft/profile/" + uuid));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
if (responseText.isEmpty()) {
debug("[httpd] query profile of {0}, not found", uuid);
return empty();
}
debug("[httpd] query profile of {0}, response: {1}", uuid, responseText);
JSONObject response = new JSONObject(responseText);
for (Object element_ : response.getJSONArray("properties")) {
JSONObject element = (JSONObject) element_;
if (property.equals(element.getString("name"))) {
return of(element.getString("value"));
}
}
return empty();
}
Aggregations