Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
🐛 Adapt upstream breaking changes PR#956
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed May 18, 2022
1 parent 008318f commit 93991bb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sourceCompatibility = 17
targetCompatibility = 17

group 'com.xtaolabs.gcauth_oauth'
version '1.1.2'
version '1.1.3'

repositories {
mavenCentral()
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/xtaolabs/gcauth_oauth/GCAuth_OAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class GCAuthAuthenticationHandler implements AuthenticationSystem {
private final Authenticator<LoginResultJson> tokenAuthenticator = new GCAuthenticators.TokenAuthenticator();
private final Authenticator<ComboTokenResJson> 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) {
Expand Down Expand Up @@ -48,4 +49,9 @@ public Authenticator<ComboTokenResJson> getSessionKeyAuthenticator() {
public ExternalAuthenticator getExternalAuthenticator() {
return externalAuthenticator;
}

@Override
public OAuthAuthenticator getOAuthAuthenticator() {
return this.oAuthAuthenticator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 93991bb

Please sign in to comment.