From 93991bb17861bee3fa38b0b344fff5f7b9bc3601 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 18 May 2022 12:10:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Adapt=20upstream=20breaking=20ch?= =?UTF-8?q?anges=20PR#956?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../xtaolabs/gcauth_oauth/GCAuth_OAuth.java | 5 +--- .../handler/GCAuthAuthenticationHandler.java | 6 +++++ .../handler/GCAuthenticators.java | 27 +++++++++++++++++++ src/main/resources/plugin.json | 2 +- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 8962124..1096c25 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ sourceCompatibility = 17 targetCompatibility = 17 group 'com.xtaolabs.gcauth_oauth' -version '1.1.2' +version '1.1.3' repositories { mavenCentral() diff --git a/src/main/java/com/xtaolabs/gcauth_oauth/GCAuth_OAuth.java b/src/main/java/com/xtaolabs/gcauth_oauth/GCAuth_OAuth.java index 5c091bb..b939f13 100644 --- a/src/main/java/com/xtaolabs/gcauth_oauth/GCAuth_OAuth.java +++ b/src/main/java/com/xtaolabs/gcauth_oauth/GCAuth_OAuth.java @@ -38,11 +38,8 @@ public class GCAuth_OAuth extends Plugin { HttpServer app = Grasscutter.getHttpServer(); - app.addRouter(JsonHandler.class); app.addRouter(RequestHandler.class); - app.addRouter(sdkHandler.class); - app.addRouter(VerifyHandler.class); - app.getHandle().config.addStaticFiles("/gcauth_oauth", folder_name, Location.EXTERNAL); + app.getHandle().config.addStaticFiles("gcauth_oauth", folder_name, Location.EXTERNAL); } } diff --git a/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthAuthenticationHandler.java b/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthAuthenticationHandler.java index aca86f7..ad7adad 100644 --- a/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthAuthenticationHandler.java +++ b/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthAuthenticationHandler.java @@ -12,6 +12,7 @@ public class GCAuthAuthenticationHandler implements AuthenticationSystem { private final Authenticator tokenAuthenticator = new GCAuthenticators.TokenAuthenticator(); private final Authenticator sessionKeyAuthenticator = new DefaultAuthenticators.SessionKeyAuthenticator(); private final GCAuthExternalAuthenticator externalAuthenticator = new GCAuthExternalAuthenticator(); + private final OAuthAuthenticator oAuthAuthenticator = new GCAuthenticators.OAuthAuthentication(); @Override public void createAccount(String username, String password) { @@ -48,4 +49,9 @@ public class GCAuthAuthenticationHandler implements AuthenticationSystem { public ExternalAuthenticator getExternalAuthenticator() { return externalAuthenticator; } + + @Override + public OAuthAuthenticator getOAuthAuthenticator() { + return this.oAuthAuthenticator; + } } diff --git a/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthenticators.java b/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthenticators.java index 7e7ed12..dcc63b8 100644 --- a/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthenticators.java +++ b/src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthenticators.java @@ -3,6 +3,7 @@ package com.xtaolabs.gcauth_oauth.handler; import emu.grasscutter.Grasscutter; import emu.grasscutter.auth.AuthenticationSystem; import emu.grasscutter.auth.Authenticator; +import emu.grasscutter.auth.OAuthAuthenticator; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.Account; import emu.grasscutter.server.http.objects.LoginResultJson; @@ -84,4 +85,30 @@ public class GCAuthenticators { return response; } } + + /** + * Handles authentication requests from OAuth sources. + */ + public static class OAuthAuthentication implements OAuthAuthenticator { + @Override + public void handleLogin(AuthenticationSystem.AuthenticationRequest request) { + assert request.getResponse() != null; + VerifyHandler.handle(request.getRequest(), request.getResponse()); + } + + @Override public void handleDesktopRedirection(AuthenticationSystem.AuthenticationRequest request) { + assert request.getResponse() != null; + JsonHandler.handle(request.getRequest(), request.getResponse()); + } + + @Override public void handleMobileRedirection(AuthenticationSystem.AuthenticationRequest request) { + assert request.getResponse() != null; + sdkHandler.handle(request.getRequest(), request.getResponse()); + } + + @Override public void handleTokenProcess(AuthenticationSystem.AuthenticationRequest request) { + assert request.getResponse() != null; + request.getResponse().send("Authentication is not available with the default authentication method."); + } + } } diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json index 478f5d5..d11aad9 100644 --- a/src/main/resources/plugin.json +++ b/src/main/resources/plugin.json @@ -1,7 +1,7 @@ { "name": "GCAuth_OAuth", "description": "The in-game login system for Grasscutter is based on oauth and GCAuth.", - "version": "1.1.2", + "version": "1.1.3", "author": ["omg-xtao"], "mainClass": "com.xtaolabs.gcauth_oauth.GCAuth_OAuth" }