From 7b7bd2480fda64311d4d645ae0d036abeb95c75d Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 27 May 2025 11:43:10 +0700 Subject: [PATCH] [FIX] Authorize in DebugMainInlineInitializer --- .../auth/core/AuthCoreProvider.java | 26 +++++++++ .../runtime/debug/ClientRuntimeProvider.java | 41 ++++---------- .../launcher/runtime/debug/DebugMain.java | 54 ++++++++++++------- .../debug/DebugMainInlineInitializer.java | 1 + .../runtime/debug/DebugProperties.java | 24 +++++++++ .../request/CurrentUserRequestEvent.java | 9 ++++ .../main/java/pro/gravit/utils/Version.java | 4 +- build.gradle | 2 +- 8 files changed, 110 insertions(+), 51 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugProperties.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java index cef6f749..09f22a28 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java @@ -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; diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/ClientRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/ClientRuntimeProvider.java index cac5dc09..eefcdf33 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/ClientRuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/ClientRuntimeProvider.java @@ -29,19 +29,14 @@ import java.util.UUID; public class ClientRuntimeProvider implements RuntimeProvider { + @Override public void run(String[] args) { ArrayList newArgs = new ArrayList<>(Arrays.asList(args)); try { - String username = System.getProperty("launcher.runtime.username", null); - String uuid = System.getProperty("launcher.runtime.uuid", null); - String login = System.getProperty("launcher.runtime.login", username); - 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 username = DebugProperties.USERNAME; + String uuid = DebugProperties.UUID; + String minecraftAccessToken = DebugProperties.MINECRAFT_ACCESS_TOKEN; String profileUUID = System.getProperty("launcher.runtime.profileuuid", null); String mainClass = System.getProperty("launcher.runtime.mainclass", 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"); } if(uuid == null) { - if(accessToken != null) { - Request.setOAuth(authId, new AuthRequestEvent.OAuthRequestEvent(accessToken, refreshToken, expire)); - Request.RequestRestoreReport report = Request.restore(true, false, true); - permissions = report.userInfo.permissions; - username = report.userInfo.playerProfile.username; - 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(); - } + var data = DebugMain.authorize(); + minecraftAccessToken = data.userInfo().accessToken; + permissions = data.userInfo().permissions; + username = data.userInfo().playerProfile.username; + uuid = data.userInfo().playerProfile.uuid.toString(); } if(profileUUID != null) { - UUID profileUuid = UUID.fromString(profileUUID); + UUID profileUuid = java.util.UUID.fromString(profileUUID); ProfilesRequest profiles = new ProfilesRequest(); ProfilesRequestEvent event = profiles.request(); for(ClientProfile profile : event.profiles) { @@ -94,7 +75,7 @@ public void run(String[] args) { replaceOrCreateArgument(newArgs, "--username", username); replaceOrCreateArgument(newArgs, "--uuid", uuid); replaceOrCreateArgument(newArgs, "--accessToken", minecraftAccessToken); - AuthService.uuid = UUID.fromString(uuid); + AuthService.uuid = java.util.UUID.fromString(uuid); AuthService.username = username; AuthService.permissions = permissions; Launch launch; diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMain.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMain.java index cecb2f28..7d00cd20 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMain.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMain.java @@ -1,7 +1,12 @@ package pro.gravit.launcher.runtime.debug; +import pro.gravit.launcher.base.ClientPermissions; import pro.gravit.launcher.base.Launcher; 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.runtime.LauncherEngine; import pro.gravit.launcher.client.RuntimeLauncherCoreModule; @@ -21,19 +26,11 @@ import java.lang.reflect.InvocationTargetException; import java.nio.file.Paths; import java.util.HashMap; +import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; public class DebugMain { 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 { LogHelper.printVersion("Launcher"); @@ -49,42 +46,63 @@ public static void initialize() throws Exception { IS_DEBUG.set(true); LogHelper.info("Launcher start in DEBUG mode (Only for developers)"); LogHelper.debug("Initialization LauncherConfig"); - LauncherConfig config = new LauncherConfig(webSocketURL, new HashMap<>(), projectName, environment, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL)); - config.unlockSecret = unlockSecret; + LauncherConfig config = new LauncherConfig(DebugProperties.WEBSOCKET_URL, new HashMap<>(), DebugProperties.PROJECT_NAME, DebugProperties.ENV, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL)); + config.unlockSecret = DebugProperties.UNLOCK_SECRET; Launcher.setConfig(config); - Launcher.applyLauncherEnv(environment); + Launcher.applyLauncherEnv(DebugProperties.ENV); LauncherEngine.modulesManager = new RuntimeModuleManager(); LauncherEngine.modulesManager.loadModule(new RuntimeLauncherCoreModule()); - for (String moduleClassName : moduleClasses) { + for (String moduleClassName : DebugProperties.MODULE_CLASSES) { if (moduleClassName.isEmpty()) continue; LauncherEngine.modulesManager.loadModule(newModule(moduleClassName)); } - for (String moduleFileName : moduleFiles) { + for (String moduleFileName : DebugProperties.MODULE_FILES) { if (moduleFileName.isEmpty()) continue; LauncherEngine.modulesManager.loadModule(Paths.get(moduleFileName)); } LauncherEngine.modulesManager.initModules(null); LauncherEngine.initGson(LauncherEngine.modulesManager); - if(!disableConsole) { + if(!DebugProperties.DISABLE_CONSOLE) { ConsoleManager.initConsole(); } LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); RequestService service; - if (offlineMode) { + if (DebugProperties.OFFLINE_MODE) { OfflineRequestService offlineRequestService = new OfflineRequestService(); ClientLauncherMethods.applyBasicOfflineProcessors(offlineRequestService); OfflineModeEvent event = new OfflineModeEvent(offlineRequestService); LauncherEngine.modulesManager.invokeEvent(event); service = event.service; } else { - service = StdWebSocketService.initWebSockets(webSocketURL).get(); + service = StdWebSocketService.initWebSockets(DebugProperties.WEBSOCKET_URL).get(); } Request.setRequestService(service); - if(!disableAutoRefresh) { + if(!DebugProperties.DISABLE_AUTO_REFRESH) { 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") public static LauncherModule newModule(String className) throws ClassNotFoundException, InvocationTargetException { Class clazz = (Class) Class.forName(className); diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMainInlineInitializer.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMainInlineInitializer.java index 2686344f..71ad9983 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMainInlineInitializer.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMainInlineInitializer.java @@ -3,5 +3,6 @@ public class DebugMainInlineInitializer { public static void run() throws Exception { DebugMain.initialize(); + DebugMain.authorize(); } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugProperties.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugProperties.java new file mode 100644 index 00000000..972b2f03 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugProperties.java @@ -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")); +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CurrentUserRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CurrentUserRequestEvent.java index f9c67018..67c30dbb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CurrentUserRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CurrentUserRequestEvent.java @@ -20,5 +20,14 @@ public static class UserInfo { public ClientPermissions permissions; public String accessToken; public PlayerProfile playerProfile; + + public UserInfo() { + } + + public UserInfo(ClientPermissions permissions, String accessToken, PlayerProfile playerProfile) { + this.permissions = permissions; + this.accessToken = accessToken; + this.playerProfile = playerProfile; + } } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index dd3bcf83..bb527f48 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,9 +6,9 @@ public final class Version implements Comparable { public static final int MAJOR = 5; 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 Version.Type RELEASE = Type.STABLE; + public static final Version.Type RELEASE = Type.DEV; public final int major; public final int minor; public final int patch; diff --git a/build.gradle b/build.gradle index 2cb7fbc8..bcbb6fa7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.1.0' apply false } group = 'pro.gravit.launcher' -version = '5.6.15' +version = '5.6.16-SNAPSHOT' apply from: 'props.gradle'