mirror of
https://github.com/unmojang/authlib-injector.git
synced 2025-09-30 23:01:29 -04:00
polyfill api.minecraftservices.com/privileges
This commit is contained in:
parent
961366e012
commit
35b8b58e1d
@ -44,6 +44,7 @@ import java.util.Set;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import moe.yushi.authlibinjector.httpd.DefaultURLRedirector;
|
import moe.yushi.authlibinjector.httpd.DefaultURLRedirector;
|
||||||
import moe.yushi.authlibinjector.httpd.LegacySkinAPIFilter;
|
import moe.yushi.authlibinjector.httpd.LegacySkinAPIFilter;
|
||||||
|
import moe.yushi.authlibinjector.httpd.PrivilegesFilter;
|
||||||
import moe.yushi.authlibinjector.httpd.QueryProfileFilter;
|
import moe.yushi.authlibinjector.httpd.QueryProfileFilter;
|
||||||
import moe.yushi.authlibinjector.httpd.QueryUUIDsFilter;
|
import moe.yushi.authlibinjector.httpd.QueryUUIDsFilter;
|
||||||
import moe.yushi.authlibinjector.httpd.URLFilter;
|
import moe.yushi.authlibinjector.httpd.URLFilter;
|
||||||
@ -239,6 +240,12 @@ public final class AuthlibInjector {
|
|||||||
log(INFO, "Disabled Mojang namespace");
|
log(INFO, "Disabled Mojang namespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean polyfillPrivilegesApi = !Boolean.TRUE.equals(config.getMeta().get("feature.privileges_api"));
|
||||||
|
if (polyfillPrivilegesApi) {
|
||||||
|
log(INFO, "Polyfill privileges API");
|
||||||
|
filters.add(new PrivilegesFilter());
|
||||||
|
}
|
||||||
|
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Haowei Wen <yushijinhun@gmail.com> and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package moe.yushi.authlibinjector.httpd;
|
||||||
|
|
||||||
|
import static moe.yushi.authlibinjector.util.IOUtils.CONTENT_TYPE_JSON;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Optional;
|
||||||
|
import moe.yushi.authlibinjector.internal.fi.iki.elonen.IHTTPSession;
|
||||||
|
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Response;
|
||||||
|
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Status;
|
||||||
|
import moe.yushi.authlibinjector.internal.org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
public class PrivilegesFilter implements URLFilter {
|
||||||
|
|
||||||
|
private static final String[] PRIVILEGES = { "onlineChat", "multiplayerServer", "multiplayerRealms" };
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canHandle(String domain) {
|
||||||
|
return domain.equals("api.minecraftservices.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Response> handle(String domain, String path, IHTTPSession session) throws IOException {
|
||||||
|
if (domain.equals("api.minecraftservices.com") && path.equals("/privileges") && session.getMethod().equals("GET")) {
|
||||||
|
JSONObject response = new JSONObject();
|
||||||
|
JSONObject privileges = new JSONObject();
|
||||||
|
for (String privilegeName : PRIVILEGES) {
|
||||||
|
JSONObject privilege = new JSONObject();
|
||||||
|
privilege.put("enabled", true);
|
||||||
|
privileges.put(privilegeName, privilege);
|
||||||
|
}
|
||||||
|
response.put("privileges", privileges);
|
||||||
|
return Optional.of(Response.newFixedLength(Status.OK, CONTENT_TYPE_JSON, response.toJSONString()));
|
||||||
|
} else {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user