Rewrote the Mojang authentication HTTP post

This commit is contained in:
Duy Tran Khanh committed 2021-02-20 16:17:35 +07:00
1 parent 3d951903c2
commit ad25e21b64
4 files changed
+106 -22

No files matched your search

@@ -4,6 +4,7 @@ import net.kdt.pojavlaunch.PojavProfile;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.authenticator.microsoft.MicrosoftAuthTask;
import net.kdt.pojavlaunch.authenticator.mojang.LoginTask;
import net.kdt.pojavlaunch.authenticator.mojang.yggdrasil.*;
import net.kdt.pojavlaunch.value.MinecraftAccount;
public class AccountJNI {
@@ -16,32 +17,40 @@ public class AccountJNI {
// Call back about account credentials for login
public static boolean loginAccount(int type,
String username, // Mojang or offline username
String password // Mojang password or Microsoft token
String data, // One of:
// Offline username
// Mojang json response
// Microsoft token
) {
try {
switch (type) {
case TYPE_SELECTACC:
CURRENT_ACCOUNT = MinecraftAccount.load(username);
CURRENT_ACCOUNT = MinecraftAccount.load(data);
if (CURRENT_ACCOUNT.isMicrosoft) {
CURRENT_ACCOUNT = new MicrosoftAuthTask().run("true", CURRENT_ACCOUNT.msaRefreshToken);
} else if (CURRENT_ACCOUNT.accessToken.length() > 5) {
PojavProfile.updateTokens(username);
PojavProfile.updateTokens(data);
}
CURRENT_ACCOUNT = MinecraftAccount.load(username);
CURRENT_ACCOUNT = MinecraftAccount.load(data);
break;
case TYPE_MICROSOFT:
CURRENT_ACCOUNT = new MicrosoftAuthTask().run("false", password);
CURRENT_ACCOUNT = new MicrosoftAuthTask().run("false", data);
break;
case TYPE_MOJANG:
CURRENT_ACCOUNT = new LoginTask().run(username, password);
AuthenticateResponse response = Tools.GLOBAL_GSON.fromJson(data, AuthenticateResponse.class);
CURRENT_ACCOUNT = new MinecraftAccount();
CURRENT_ACCOUNT.accessToken = response.accessToken;
CURRENT_ACCOUNT.clientToken = response.clientToken.toString();
CURRENT_ACCOUNT.profileId = response.selectedProfile.id;
CURRENT_ACCOUNT.username = response.selectedProfile.name;
CURRENT_ACCOUNT.save();
break;
case TYPE_OFFLINE:
CURRENT_ACCOUNT = new MinecraftAccount();
CURRENT_ACCOUNT.username = username;
CURRENT_ACCOUNT.username = data;
CURRENT_ACCOUNT.save();
break;
}