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 void loadTwitterLogin() { 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 Authenticator getSessionKeyAuthenticator() { 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 @@ 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 LoginResultJson authenticate(AuthenticationSystem.AuthenticationRequest r 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" }