[FIX] JsonAuthCoreProvider joinServer/checkServer

This commit is contained in:
Gravita 2021-08-08 16:10:07 +07:00
parent 9fff11e887
commit a915d41b93
2 changed files with 46 additions and 1 deletions

View file

@ -37,6 +37,8 @@ public class JsonCoreProvider extends AuthCoreProvider {
public String verifyPasswordUrl;
public String createOAuthSessionUrl;
public String updateServerIdUrl;
public String joinServerUrl;
public String checkServerUrl;
public String bearerToken;
public PasswordVerifier passwordVerifier;
private transient HttpClient client;
@ -159,8 +161,29 @@ public void init(LaunchServer server) {
client = HttpClient.newBuilder().build();
}
@Override
public User checkServer(Client client, String username, String serverID) throws IOException {
if (checkServerUrl == null) {
return super.checkServer(client, username, serverID);
}
return jsonRequest(new JsonCheckServer(username, serverID), checkServerUrl, JsonUser.class);
}
@Override
public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException {
if (joinServerUrl == null) {
return super.joinServer(client, username, accessToken, serverID);
}
return jsonRequest(new JsonJoinServer(username, accessToken, serverID), joinServerUrl, JsonSuccessResponse.class).success;
}
@Override
protected boolean updateServerID(User user, String serverID) throws IOException {
JsonUser jsonUser = (JsonUser) user;
if (updateServerIdUrl == null) {
return false;
}
jsonUser.serverId = serverID;
JsonSuccessResponse successResponse = jsonRequest(new JsonUpdateServerId(user.getUsername(), user.getUUID(), serverID), updateServerIdUrl, JsonSuccessResponse.class);
if (successResponse == null) return false;
return successResponse.success;
@ -183,6 +206,28 @@ public JsonGetUserByUsername(String username) {
}
}
public static class JsonCheckServer {
public String username;
public String serverId;
public JsonCheckServer(String username, String serverId) {
this.username = username;
this.serverId = serverId;
}
}
public static class JsonJoinServer {
public String username;
public String accessToken;
public String serverId;
public JsonJoinServer(String username, String accessToken, String serverId) {
this.username = username;
this.accessToken = accessToken;
this.serverId = serverId;
}
}
public static class JsonGetUserByUUID {
public UUID uuid;

View file

@ -112,7 +112,7 @@ public void verifyAuth(AuthResponse.AuthContext context) throws AuthException {
@Override
public PasswordVerifyReport verifyPassword(User user, AuthRequest.AuthPasswordInterface password) {
if (passwordVerifier.check(((MySQLUser) user).password, ((AuthPlainPassword) password).password)) {
return new PasswordVerifyReport(true);
return PasswordVerifyReport.OK;
} else {
return PasswordVerifyReport.FAILED;
}