diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java index 04a33bf4a..a28fa5163 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java @@ -22,6 +22,7 @@ import org.jackhuang.hmcl.auth.AuthenticationException; import org.jackhuang.hmcl.auth.microsoft.MicrosoftService; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.util.Logging; +import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.io.IOUtils; import org.jackhuang.hmcl.util.io.JarUtils; import org.jackhuang.hmcl.util.io.NetworkUtils; @@ -74,7 +75,7 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi String html; try { html = IOUtils.readFullyAsString(MicrosoftAuthenticationServer.class.getResourceAsStream("/assets/microsoft_auth.html"), StandardCharsets.UTF_8) - .replace("%close-page%", i18n("account.methods.microsoft.close_page")); + .replace("%close-page%", i18n("account.methods.microsoft.close_page")); } catch (IOException e) { Logging.LOG.log(Level.SEVERE, "Failed to load html"); return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, MIME_HTML, ""); @@ -93,7 +94,11 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi public static class Factory implements MicrosoftService.OAuthCallback { @Override - public MicrosoftService.OAuthSession startServer() throws IOException { + public MicrosoftService.OAuthSession startServer() throws IOException, AuthenticationException { + if (StringUtils.isBlank(getClientId())) { + throw new MicrosoftAuthenticationNotSupportedException(); + } + IOException exception = null; for (int port : new int[]{29111, 29112, 29113, 29114, 29115}) { try { @@ -126,4 +131,7 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi } } + + public static class MicrosoftAuthenticationNotSupportedException extends AuthenticationException { + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java index 8471e2a67..c8bacc7cb 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java @@ -378,6 +378,8 @@ public final class Accounts { return i18n("account.methods.microsoft.error.no_character"); } else if (exception instanceof MicrosoftService.NoXuiException) { return i18n("account.methods.microsoft.error.add_family_probably"); + } else if (exception instanceof MicrosoftAuthenticationServer.MicrosoftAuthenticationNotSupportedException) { + return i18n("account.methods.microsoft.snapshot"); } else if (exception.getClass() == AuthenticationException.class) { return exception.getLocalizedMessage(); } else { diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 5d8f752a9..c2f242f5c 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -91,6 +91,7 @@ account.methods.microsoft.logging_in=Logging in... account.methods.microsoft.hint=You should click "login" button and continue login process in newly opened browser window. account.methods.microsoft.manual=After clicking "login" button, you should finish authorization in the newly opened browser window. If the browser window failed to show, you can click here to copy the URL, and manually open it in your browser. account.methods.microsoft.profile=Account Profile... +account.methods.microsoft.snapshot=HMCL Snapshot version does not support Microsoft login. account.methods.microsoft.waiting_browser=Waiting for authorization in opened browser window... account.methods.offline=Offline account.methods.offline.uuid=UUID diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 122e7ad1e..49a9e2a53 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -91,6 +91,7 @@ account.methods.microsoft.logging_in=登入中... account.methods.microsoft.hint=您需要點擊登入按鈕,並在新打開的瀏覽器窗口中完成登入。 account.methods.microsoft.manual=若登入頁面未能打開,您可以點擊此處複製連結,並手動在瀏覽器中打開網頁。 account.methods.microsoft.profile=帳戶設置頁 +account.methods.microsoft.snapshot=HMCL 快照版不支持微软登录 account.methods.microsoft.waiting_browser=等待在新打開的瀏覽器窗口中完成登入... account.methods.offline=離線模式 account.methods.offline.uuid=UUID diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 98978e618..33295d5ea 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -91,6 +91,7 @@ account.methods.microsoft.logging_in=登录中... account.methods.microsoft.hint=您需要点击登录按钮,并在新打开的浏览器窗口中完成登录。 account.methods.microsoft.manual=若登录页面未能打开,您可以点击此处复制链接,并手动在浏览器中打开网页。 account.methods.microsoft.profile=帐户设置页 +account.methods.microsoft.snapshot=HMCL 快照版不支持微软登录 account.methods.microsoft.waiting_browser=等待在新打开的浏览器窗口中完成登录... account.methods.offline=离线模式 account.methods.offline.uuid=UUID diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java index 9d938edcc..7e168e31e 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java @@ -504,7 +504,7 @@ public class MicrosoftService { * * @throws IOException if an I/O error occurred. */ - OAuthSession startServer() throws IOException; + OAuthSession startServer() throws IOException, AuthenticationException; /** * Open browser