mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-06-06 22:37:01 +03:00
[FIX] Authorize in DebugMainInlineInitializer
This commit is contained in:
parent
124c384971
commit
7b7bd2480f
8 changed files with 110 additions and 51 deletions
|
@ -338,6 +338,32 @@ public void invoke(String... args) throws Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
map.put("newSession", new SubCommand("[username/uuid] [isShadow] (CLIENT/API)", "create access/refresh token without password") {
|
||||||
|
@Override
|
||||||
|
public void invoke(String... args) throws Exception {
|
||||||
|
verifyArgs(args, 2);
|
||||||
|
String login = args[0];
|
||||||
|
boolean isShadow = Boolean.parseBoolean(args[1]);
|
||||||
|
User user;
|
||||||
|
if(login.length() == 36) {
|
||||||
|
UUID uuid = UUID.fromString(login);
|
||||||
|
user = getUserByUUID(uuid);
|
||||||
|
} else {
|
||||||
|
user = getUserByUsername(login);
|
||||||
|
}
|
||||||
|
if(user == null) {
|
||||||
|
logger.error("User {} not found", login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var report = instance.sudo(user, isShadow);
|
||||||
|
User user1 = report.session().getUser();
|
||||||
|
logger.info("Created session {} for user {} ({})", report.session().getID(), user1.getUsername(), user.getUUID());
|
||||||
|
logger.info("- AccessToken: {}", report.oauthAccessToken());
|
||||||
|
logger.info("- RefreshToken: {}", report.oauthRefreshToken());
|
||||||
|
logger.info("- ExpireIn: {}", report.oauthExpire());
|
||||||
|
logger.info("- MinecraftAccessToken: {}", report.minecraftAccessToken());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
|
|
@ -29,19 +29,14 @@
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ClientRuntimeProvider implements RuntimeProvider {
|
public class ClientRuntimeProvider implements RuntimeProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String[] args) {
|
public void run(String[] args) {
|
||||||
ArrayList<String> newArgs = new ArrayList<>(Arrays.asList(args));
|
ArrayList<String> newArgs = new ArrayList<>(Arrays.asList(args));
|
||||||
try {
|
try {
|
||||||
String username = System.getProperty("launcher.runtime.username", null);
|
String username = DebugProperties.USERNAME;
|
||||||
String uuid = System.getProperty("launcher.runtime.uuid", null);
|
String uuid = DebugProperties.UUID;
|
||||||
String login = System.getProperty("launcher.runtime.login", username);
|
String minecraftAccessToken = DebugProperties.MINECRAFT_ACCESS_TOKEN;
|
||||||
String password = System.getProperty("launcher.runtime.password", "Player");
|
|
||||||
String authId = System.getProperty("launcher.runtime.auth.authid", "std");
|
|
||||||
String accessToken = System.getProperty("launcher.runtime.auth.accesstoken", null);
|
|
||||||
String refreshToken = System.getProperty("launcher.runtime.auth.refreshtoken", null);
|
|
||||||
String minecraftAccessToken = System.getProperty("launcher.runtime.auth.minecraftaccesstoken", "DEBUG");
|
|
||||||
long expire = Long.parseLong(System.getProperty("launcher.runtime.auth.expire", "0"));
|
|
||||||
String profileUUID = System.getProperty("launcher.runtime.profileuuid", null);
|
String profileUUID = System.getProperty("launcher.runtime.profileuuid", null);
|
||||||
String mainClass = System.getProperty("launcher.runtime.mainclass", null);
|
String mainClass = System.getProperty("launcher.runtime.mainclass", null);
|
||||||
String mainModule = System.getProperty("launcher.runtime.mainmodule", null);
|
String mainModule = System.getProperty("launcher.runtime.mainmodule", null);
|
||||||
|
@ -55,28 +50,14 @@ public void run(String[] args) {
|
||||||
throw new NullPointerException("Add `-Dlauncher.runtime.mainclass=YOUR_MAIN_CLASS` to jvmArgs");
|
throw new NullPointerException("Add `-Dlauncher.runtime.mainclass=YOUR_MAIN_CLASS` to jvmArgs");
|
||||||
}
|
}
|
||||||
if(uuid == null) {
|
if(uuid == null) {
|
||||||
if(accessToken != null) {
|
var data = DebugMain.authorize();
|
||||||
Request.setOAuth(authId, new AuthRequestEvent.OAuthRequestEvent(accessToken, refreshToken, expire));
|
minecraftAccessToken = data.userInfo().accessToken;
|
||||||
Request.RequestRestoreReport report = Request.restore(true, false, true);
|
permissions = data.userInfo().permissions;
|
||||||
permissions = report.userInfo.permissions;
|
username = data.userInfo().playerProfile.username;
|
||||||
username = report.userInfo.playerProfile.username;
|
uuid = data.userInfo().playerProfile.uuid.toString();
|
||||||
uuid = report.userInfo.playerProfile.uuid.toString();
|
|
||||||
if(report.userInfo.accessToken != null) {
|
|
||||||
minecraftAccessToken = report.userInfo.accessToken;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
AuthRequest request = new AuthRequest(login, password, authId, AuthRequest.ConnectTypes.API);
|
|
||||||
AuthRequestEvent event = request.request();
|
|
||||||
Request.setOAuth(authId, event.oauth);
|
|
||||||
if(event.accessToken != null) {
|
|
||||||
minecraftAccessToken = event.accessToken;
|
|
||||||
}
|
|
||||||
username = event.playerProfile.username;
|
|
||||||
uuid = event.playerProfile.uuid.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(profileUUID != null) {
|
if(profileUUID != null) {
|
||||||
UUID profileUuid = UUID.fromString(profileUUID);
|
UUID profileUuid = java.util.UUID.fromString(profileUUID);
|
||||||
ProfilesRequest profiles = new ProfilesRequest();
|
ProfilesRequest profiles = new ProfilesRequest();
|
||||||
ProfilesRequestEvent event = profiles.request();
|
ProfilesRequestEvent event = profiles.request();
|
||||||
for(ClientProfile profile : event.profiles) {
|
for(ClientProfile profile : event.profiles) {
|
||||||
|
@ -94,7 +75,7 @@ public void run(String[] args) {
|
||||||
replaceOrCreateArgument(newArgs, "--username", username);
|
replaceOrCreateArgument(newArgs, "--username", username);
|
||||||
replaceOrCreateArgument(newArgs, "--uuid", uuid);
|
replaceOrCreateArgument(newArgs, "--uuid", uuid);
|
||||||
replaceOrCreateArgument(newArgs, "--accessToken", minecraftAccessToken);
|
replaceOrCreateArgument(newArgs, "--accessToken", minecraftAccessToken);
|
||||||
AuthService.uuid = UUID.fromString(uuid);
|
AuthService.uuid = java.util.UUID.fromString(uuid);
|
||||||
AuthService.username = username;
|
AuthService.username = username;
|
||||||
AuthService.permissions = permissions;
|
AuthService.permissions = permissions;
|
||||||
Launch launch;
|
Launch launch;
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package pro.gravit.launcher.runtime.debug;
|
package pro.gravit.launcher.runtime.debug;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.base.ClientPermissions;
|
||||||
import pro.gravit.launcher.base.Launcher;
|
import pro.gravit.launcher.base.Launcher;
|
||||||
import pro.gravit.launcher.base.LauncherConfig;
|
import pro.gravit.launcher.base.LauncherConfig;
|
||||||
|
import pro.gravit.launcher.base.events.request.AuthRequestEvent;
|
||||||
|
import pro.gravit.launcher.base.events.request.CurrentUserRequestEvent;
|
||||||
|
import pro.gravit.launcher.base.profiles.PlayerProfile;
|
||||||
|
import pro.gravit.launcher.base.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.client.ClientLauncherMethods;
|
import pro.gravit.launcher.client.ClientLauncherMethods;
|
||||||
import pro.gravit.launcher.runtime.LauncherEngine;
|
import pro.gravit.launcher.runtime.LauncherEngine;
|
||||||
import pro.gravit.launcher.client.RuntimeLauncherCoreModule;
|
import pro.gravit.launcher.client.RuntimeLauncherCoreModule;
|
||||||
|
@ -21,19 +26,11 @@
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class DebugMain {
|
public class DebugMain {
|
||||||
public static final AtomicBoolean IS_DEBUG = new AtomicBoolean(false);
|
public static final AtomicBoolean IS_DEBUG = new AtomicBoolean(false);
|
||||||
public static String webSocketURL = System.getProperty("launcherdebug.websocket", "ws://localhost:9274/api");
|
|
||||||
public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft");
|
|
||||||
public static String unlockSecret = System.getProperty("launcherdebug.unlocksecret", "");
|
|
||||||
public static boolean disableConsole = Boolean.getBoolean("launcherdebug.disableConsole");
|
|
||||||
public static boolean offlineMode = Boolean.getBoolean("launcherdebug.offlinemode");
|
|
||||||
public static boolean disableAutoRefresh = Boolean.getBoolean("launcherdebug.disableautorefresh");
|
|
||||||
public static String[] moduleClasses = System.getProperty("launcherdebug.modules", "").split(",");
|
|
||||||
public static String[] moduleFiles = System.getProperty("launcherdebug.modulefiles", "").split(",");
|
|
||||||
public static LauncherConfig.LauncherEnvironment environment = LauncherConfig.LauncherEnvironment.valueOf(System.getProperty("launcherdebug.env", "STD"));
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
LogHelper.printVersion("Launcher");
|
LogHelper.printVersion("Launcher");
|
||||||
|
@ -49,42 +46,63 @@ public static void initialize() throws Exception {
|
||||||
IS_DEBUG.set(true);
|
IS_DEBUG.set(true);
|
||||||
LogHelper.info("Launcher start in DEBUG mode (Only for developers)");
|
LogHelper.info("Launcher start in DEBUG mode (Only for developers)");
|
||||||
LogHelper.debug("Initialization LauncherConfig");
|
LogHelper.debug("Initialization LauncherConfig");
|
||||||
LauncherConfig config = new LauncherConfig(webSocketURL, new HashMap<>(), projectName, environment, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL));
|
LauncherConfig config = new LauncherConfig(DebugProperties.WEBSOCKET_URL, new HashMap<>(), DebugProperties.PROJECT_NAME, DebugProperties.ENV, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL));
|
||||||
config.unlockSecret = unlockSecret;
|
config.unlockSecret = DebugProperties.UNLOCK_SECRET;
|
||||||
Launcher.setConfig(config);
|
Launcher.setConfig(config);
|
||||||
Launcher.applyLauncherEnv(environment);
|
Launcher.applyLauncherEnv(DebugProperties.ENV);
|
||||||
LauncherEngine.modulesManager = new RuntimeModuleManager();
|
LauncherEngine.modulesManager = new RuntimeModuleManager();
|
||||||
LauncherEngine.modulesManager.loadModule(new RuntimeLauncherCoreModule());
|
LauncherEngine.modulesManager.loadModule(new RuntimeLauncherCoreModule());
|
||||||
for (String moduleClassName : moduleClasses) {
|
for (String moduleClassName : DebugProperties.MODULE_CLASSES) {
|
||||||
if (moduleClassName.isEmpty()) continue;
|
if (moduleClassName.isEmpty()) continue;
|
||||||
LauncherEngine.modulesManager.loadModule(newModule(moduleClassName));
|
LauncherEngine.modulesManager.loadModule(newModule(moduleClassName));
|
||||||
}
|
}
|
||||||
for (String moduleFileName : moduleFiles) {
|
for (String moduleFileName : DebugProperties.MODULE_FILES) {
|
||||||
if (moduleFileName.isEmpty()) continue;
|
if (moduleFileName.isEmpty()) continue;
|
||||||
LauncherEngine.modulesManager.loadModule(Paths.get(moduleFileName));
|
LauncherEngine.modulesManager.loadModule(Paths.get(moduleFileName));
|
||||||
}
|
}
|
||||||
LauncherEngine.modulesManager.initModules(null);
|
LauncherEngine.modulesManager.initModules(null);
|
||||||
LauncherEngine.initGson(LauncherEngine.modulesManager);
|
LauncherEngine.initGson(LauncherEngine.modulesManager);
|
||||||
if(!disableConsole) {
|
if(!DebugProperties.DISABLE_CONSOLE) {
|
||||||
ConsoleManager.initConsole();
|
ConsoleManager.initConsole();
|
||||||
}
|
}
|
||||||
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
|
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
|
||||||
RequestService service;
|
RequestService service;
|
||||||
if (offlineMode) {
|
if (DebugProperties.OFFLINE_MODE) {
|
||||||
OfflineRequestService offlineRequestService = new OfflineRequestService();
|
OfflineRequestService offlineRequestService = new OfflineRequestService();
|
||||||
ClientLauncherMethods.applyBasicOfflineProcessors(offlineRequestService);
|
ClientLauncherMethods.applyBasicOfflineProcessors(offlineRequestService);
|
||||||
OfflineModeEvent event = new OfflineModeEvent(offlineRequestService);
|
OfflineModeEvent event = new OfflineModeEvent(offlineRequestService);
|
||||||
LauncherEngine.modulesManager.invokeEvent(event);
|
LauncherEngine.modulesManager.invokeEvent(event);
|
||||||
service = event.service;
|
service = event.service;
|
||||||
} else {
|
} else {
|
||||||
service = StdWebSocketService.initWebSockets(webSocketURL).get();
|
service = StdWebSocketService.initWebSockets(DebugProperties.WEBSOCKET_URL).get();
|
||||||
}
|
}
|
||||||
Request.setRequestService(service);
|
Request.setRequestService(service);
|
||||||
if(!disableAutoRefresh) {
|
if(!DebugProperties.DISABLE_AUTO_REFRESH) {
|
||||||
Request.startAutoRefresh();
|
Request.startAutoRefresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AuthorizationData authorize() throws Exception {
|
||||||
|
if(DebugProperties.ACCESS_TOKEN != null) {
|
||||||
|
Request.setOAuth(DebugProperties.AUTH_ID, new AuthRequestEvent.OAuthRequestEvent(DebugProperties.ACCESS_TOKEN, DebugProperties.REFRESH_TOKEN, DebugProperties.EXPIRE));
|
||||||
|
Request.RequestRestoreReport report = Request.restore(true, false, true);
|
||||||
|
return new AuthorizationData(new AuthRequestEvent.OAuthRequestEvent(DebugProperties.ACCESS_TOKEN, DebugProperties.REFRESH_TOKEN, DebugProperties.EXPIRE), report.userInfo);
|
||||||
|
} else if(DebugProperties.LOGIN != null) {
|
||||||
|
AuthRequest request = new AuthRequest(DebugProperties.LOGIN, DebugProperties.PASSWORD, DebugProperties.AUTH_ID, AuthRequest.ConnectTypes.API);
|
||||||
|
AuthRequestEvent event = request.request();
|
||||||
|
Request.setOAuth(DebugProperties.AUTH_ID, event.oauth);
|
||||||
|
return new AuthorizationData(event.oauth, new CurrentUserRequestEvent.UserInfo(event.permissions, event.accessToken, event.playerProfile));
|
||||||
|
} else {
|
||||||
|
return new AuthorizationData(new AuthRequestEvent.OAuthRequestEvent("ACCESS_TOKEN", "REFRESH_TOKEN", 0),
|
||||||
|
new CurrentUserRequestEvent.UserInfo(new ClientPermissions(), "ACCESS_TOKEN", new PlayerProfile(UUID.fromString(DebugProperties.UUID),
|
||||||
|
DebugProperties.USERNAME, new HashMap<>(), new HashMap<>())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record AuthorizationData(AuthRequestEvent.OAuthRequestEvent event, CurrentUserRequestEvent.UserInfo userInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static LauncherModule newModule(String className) throws ClassNotFoundException, InvocationTargetException {
|
public static LauncherModule newModule(String className) throws ClassNotFoundException, InvocationTargetException {
|
||||||
Class<? extends LauncherModule> clazz = (Class<? extends LauncherModule>) Class.forName(className);
|
Class<? extends LauncherModule> clazz = (Class<? extends LauncherModule>) Class.forName(className);
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
public class DebugMainInlineInitializer {
|
public class DebugMainInlineInitializer {
|
||||||
public static void run() throws Exception {
|
public static void run() throws Exception {
|
||||||
DebugMain.initialize();
|
DebugMain.initialize();
|
||||||
|
DebugMain.authorize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package pro.gravit.launcher.runtime.debug;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.base.LauncherConfig;
|
||||||
|
|
||||||
|
public class DebugProperties {
|
||||||
|
public static final String ACCESS_TOKEN = System.getProperty("launcher.runtime.auth.accesstoken", null);
|
||||||
|
public static final String AUTH_ID = System.getProperty("launcher.runtime.auth.authid", "std");
|
||||||
|
public static final String REFRESH_TOKEN = System.getProperty("launcher.runtime.auth.refreshtoken", null);
|
||||||
|
public static final String MINECRAFT_ACCESS_TOKEN = System.getProperty("launcher.runtime.auth.minecraftaccesstoken", "DEBUG");
|
||||||
|
public static final long EXPIRE = Long.parseLong(System.getProperty("launcher.runtime.auth.expire", "0"));
|
||||||
|
public static final String USERNAME = System.getProperty("launcher.runtime.username", null);
|
||||||
|
public static final String LOGIN = System.getProperty("launcher.runtime.login", USERNAME);
|
||||||
|
public static final String UUID = System.getProperty("launcher.runtime.uuid", null);
|
||||||
|
public static final String PASSWORD = System.getProperty("launcher.runtime.password", null);
|
||||||
|
public static String WEBSOCKET_URL = System.getProperty("launcherdebug.websocket", "ws://localhost:9274/api");
|
||||||
|
public static String PROJECT_NAME = System.getProperty("launcherdebug.projectname", "Minecraft");
|
||||||
|
public static String UNLOCK_SECRET = System.getProperty("launcherdebug.unlocksecret", "");
|
||||||
|
public static boolean DISABLE_CONSOLE = Boolean.getBoolean("launcherdebug.disableConsole");
|
||||||
|
public static boolean OFFLINE_MODE = Boolean.getBoolean("launcherdebug.offlinemode");
|
||||||
|
public static boolean DISABLE_AUTO_REFRESH = Boolean.getBoolean("launcherdebug.disableautorefresh");
|
||||||
|
public static String[] MODULE_CLASSES = System.getProperty("launcherdebug.modules", "").split(",");
|
||||||
|
public static String[] MODULE_FILES = System.getProperty("launcherdebug.modulefiles", "").split(",");
|
||||||
|
public static LauncherConfig.LauncherEnvironment ENV = LauncherConfig.LauncherEnvironment.valueOf(System.getProperty("launcherdebug.env", "STD"));
|
||||||
|
}
|
|
@ -20,5 +20,14 @@ public static class UserInfo {
|
||||||
public ClientPermissions permissions;
|
public ClientPermissions permissions;
|
||||||
public String accessToken;
|
public String accessToken;
|
||||||
public PlayerProfile playerProfile;
|
public PlayerProfile playerProfile;
|
||||||
|
|
||||||
|
public UserInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserInfo(ClientPermissions permissions, String accessToken, PlayerProfile playerProfile) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
this.playerProfile = playerProfile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ public final class Version implements Comparable<Version> {
|
||||||
|
|
||||||
public static final int MAJOR = 5;
|
public static final int MAJOR = 5;
|
||||||
public static final int MINOR = 6;
|
public static final int MINOR = 6;
|
||||||
public static final int PATCH = 15;
|
public static final int PATCH = 16;
|
||||||
public static final int BUILD = 1;
|
public static final int BUILD = 1;
|
||||||
public static final Version.Type RELEASE = Type.STABLE;
|
public static final Version.Type RELEASE = Type.DEV;
|
||||||
public final int major;
|
public final int major;
|
||||||
public final int minor;
|
public final int minor;
|
||||||
public final int patch;
|
public final int patch;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
id 'org.openjfx.javafxplugin' version '0.1.0' apply false
|
id 'org.openjfx.javafxplugin' version '0.1.0' apply false
|
||||||
}
|
}
|
||||||
group = 'pro.gravit.launcher'
|
group = 'pro.gravit.launcher'
|
||||||
version = '5.6.15'
|
version = '5.6.16-SNAPSHOT'
|
||||||
|
|
||||||
apply from: 'props.gradle'
|
apply from: 'props.gradle'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue