This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⬆️ Support gc-dev-1.1.2 gcauth-2.2.1
- Loading branch information
Showing
10 changed files
with
175 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthAuthenticationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.xtaolabs.gcauth_oauth.handler; | ||
|
||
import emu.grasscutter.auth.*; | ||
import emu.grasscutter.server.http.objects.ComboTokenResJson; | ||
import emu.grasscutter.server.http.objects.LoginResultJson; | ||
|
||
import me.exzork.gcauth.handler.GCAuthExternalAuthenticator; | ||
|
||
public class GCAuthAuthenticationHandler implements AuthenticationSystem { | ||
private final Authenticator<LoginResultJson> gcAuthAuthenticator = new GCAuthenticators.GCAuthAuthenticator(); | ||
private final Authenticator<LoginResultJson> tokenAuthenticator = new DefaultAuthenticators.TokenAuthenticator(); | ||
private final Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new DefaultAuthenticators.SessionKeyAuthenticator(); | ||
private final GCAuthExternalAuthenticator externalAuthenticator = new GCAuthExternalAuthenticator(); | ||
|
||
@Override | ||
public void createAccount(String username, String password) { | ||
// Unhandled. | ||
} | ||
|
||
@Override | ||
public void resetPassword(String username) { | ||
// Unhandled. | ||
} | ||
|
||
@Override | ||
public boolean verifyUser(String s) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Authenticator<LoginResultJson> getPasswordAuthenticator() { | ||
return gcAuthAuthenticator; | ||
} | ||
|
||
@Override | ||
public Authenticator<LoginResultJson> getTokenAuthenticator() { | ||
return tokenAuthenticator; | ||
} | ||
|
||
@Override | ||
public Authenticator<ComboTokenResJson> getSessionKeyAuthenticator() { | ||
return sessionKeyAuthenticator; | ||
} | ||
|
||
@Override | ||
public ExternalAuthenticator getExternalAuthenticator() { | ||
return externalAuthenticator; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/xtaolabs/gcauth_oauth/handler/GCAuthenticators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.xtaolabs.gcauth_oauth.handler; | ||
|
||
import emu.grasscutter.Grasscutter; | ||
import emu.grasscutter.auth.AuthenticationSystem; | ||
import emu.grasscutter.auth.Authenticator; | ||
import emu.grasscutter.game.Account; | ||
import emu.grasscutter.server.http.objects.LoginResultJson; | ||
|
||
import me.exzork.gcauth.utils.Authentication; | ||
|
||
public class GCAuthenticators { | ||
|
||
public static class GCAuthAuthenticator implements Authenticator<LoginResultJson> { | ||
|
||
@Override | ||
public LoginResultJson authenticate(AuthenticationSystem.AuthenticationRequest authenticationRequest) { | ||
var response = new LoginResultJson(); | ||
|
||
var requestData = authenticationRequest.getPasswordRequest(); | ||
assert requestData != null; // This should never be null. | ||
|
||
Account account = Authentication.getAccountByOneTimeToken(requestData.account); | ||
if(account == null) { | ||
Grasscutter.getLogger().info("[GCAuth] Client " + requestData.account + " tried to login with invalid one time token."); | ||
response.retcode = -201; | ||
response.message = "Token is invalid"; | ||
return response; | ||
} | ||
|
||
// Account was found, log the player in | ||
response.message = "OK"; | ||
response.data.account.uid = account.getId(); | ||
response.data.account.token = account.generateSessionKey(); | ||
response.data.account.email = account.getEmail(); | ||
response.data.account.twitter_name = account.getUsername(); | ||
|
||
Grasscutter.getLogger().info("[GCAuth] Client " + requestData.account + " logged in"); | ||
return response; | ||
} | ||
} | ||
} |
23 changes: 14 additions & 9 deletions
23
src/main/java/com/xtaolabs/gcauth_oauth/handler/JsonHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 12 additions & 5 deletions
17
src/main/java/com/xtaolabs/gcauth_oauth/handler/RequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 16 additions & 6 deletions
22
src/main/java/com/xtaolabs/gcauth_oauth/handler/VerifyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/xtaolabs/gcauth_oauth/handler/sdkHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.xtaolabs.gcauth_oauth.handler; | ||
|
||
import emu.grasscutter.server.http.Router; | ||
import static emu.grasscutter.Configuration.*; | ||
|
||
import express.Express; | ||
import express.http.Request; | ||
import express.http.Response; | ||
|
||
import io.javalin.Javalin; | ||
|
||
|
||
public final class sdkHandler implements Router { | ||
|
||
@Override | ||
public void applyRoutes(Express express, Javalin javalin) { | ||
express.get("/sdkTwitterLogin.html", sdkHandler::handle); | ||
} | ||
|
||
public static void handle(Request req, Response res) { | ||
String Login_Url = ("http" + (HTTP_ENCRYPTION.useEncryption ? "s" : "") + "://" | ||
+ lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress) + ":" | ||
+ lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort) + "/gcauth_oauth/login.html"); | ||
res.send(String.format("<meta http-equiv=\"refresh\" content=\"0;url=%s\">", Login_Url)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ public static DecodedJWT deToken(final String token) { | |
} | ||
return jwt; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.0.0", | ||
"version": "1.1.0", | ||
"author": ["omg-xtao"], | ||
"mainClass": "com.xtaolabs.gcauth_oauth.GCAuth_OAuth" | ||
} |