🐛 Adapt upstream breaking changes PR#956

This commit is contained in:
xtaodada 2022-05-18 12:10:08 +08:00
parent 008318fae1
commit 93991bb178
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
5 changed files with 36 additions and 6 deletions

View File

@ -10,7 +10,7 @@ sourceCompatibility = 17
targetCompatibility = 17 targetCompatibility = 17
group 'com.xtaolabs.gcauth_oauth' group 'com.xtaolabs.gcauth_oauth'
version '1.1.2' version '1.1.3'
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -38,11 +38,8 @@ public class GCAuth_OAuth extends Plugin {
HttpServer app = Grasscutter.getHttpServer(); HttpServer app = Grasscutter.getHttpServer();
app.addRouter(JsonHandler.class);
app.addRouter(RequestHandler.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);
} }
} }

View File

@ -12,6 +12,7 @@ public class GCAuthAuthenticationHandler implements AuthenticationSystem {
private final Authenticator<LoginResultJson> tokenAuthenticator = new GCAuthenticators.TokenAuthenticator(); private final Authenticator<LoginResultJson> tokenAuthenticator = new GCAuthenticators.TokenAuthenticator();
private final Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new DefaultAuthenticators.SessionKeyAuthenticator(); private final Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new DefaultAuthenticators.SessionKeyAuthenticator();
private final GCAuthExternalAuthenticator externalAuthenticator = new GCAuthExternalAuthenticator(); private final GCAuthExternalAuthenticator externalAuthenticator = new GCAuthExternalAuthenticator();
private final OAuthAuthenticator oAuthAuthenticator = new GCAuthenticators.OAuthAuthentication();
@Override @Override
public void createAccount(String username, String password) { public void createAccount(String username, String password) {
@ -48,4 +49,9 @@ public class GCAuthAuthenticationHandler implements AuthenticationSystem {
public ExternalAuthenticator getExternalAuthenticator() { public ExternalAuthenticator getExternalAuthenticator() {
return externalAuthenticator; return externalAuthenticator;
} }
@Override
public OAuthAuthenticator getOAuthAuthenticator() {
return this.oAuthAuthenticator;
}
} }

View File

@ -3,6 +3,7 @@ package com.xtaolabs.gcauth_oauth.handler;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.auth.AuthenticationSystem; import emu.grasscutter.auth.AuthenticationSystem;
import emu.grasscutter.auth.Authenticator; import emu.grasscutter.auth.Authenticator;
import emu.grasscutter.auth.OAuthAuthenticator;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account; import emu.grasscutter.game.Account;
import emu.grasscutter.server.http.objects.LoginResultJson; import emu.grasscutter.server.http.objects.LoginResultJson;
@ -84,4 +85,30 @@ public class GCAuthenticators {
return response; 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.");
}
}
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "GCAuth_OAuth", "name": "GCAuth_OAuth",
"description": "The in-game login system for Grasscutter is based on oauth and GCAuth.", "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"], "author": ["omg-xtao"],
"mainClass": "com.xtaolabs.gcauth_oauth.GCAuth_OAuth" "mainClass": "com.xtaolabs.gcauth_oauth.GCAuth_OAuth"
} }