mirror of
https://github.com/exzork/GCAuth.git
synced 2024-11-24 00:23:58 +00:00
commit
9d991b2749
@ -3,7 +3,10 @@ package me.exzork.gcauth;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
|
import emu.grasscutter.auth.DefaultAuthentication;
|
||||||
import emu.grasscutter.plugin.Plugin;
|
import emu.grasscutter.plugin.Plugin;
|
||||||
|
import static emu.grasscutter.Configuration.ACCOUNT;
|
||||||
|
|
||||||
import me.exzork.gcauth.handler.*;
|
import me.exzork.gcauth.handler.*;
|
||||||
import me.exzork.gcauth.utils.Authentication;
|
import me.exzork.gcauth.utils.Authentication;
|
||||||
|
|
||||||
@ -34,14 +37,14 @@ public class GCAuth extends Plugin {
|
|||||||
getLogger().info("GCAuth Enabled!");
|
getLogger().info("GCAuth Enabled!");
|
||||||
config.jwtSecret = Authentication.generateRandomString(32);
|
config.jwtSecret = Authentication.generateRandomString(32);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
if (Grasscutter.getConfig().account.autoCreate) {
|
if (ACCOUNT.autoCreate) {
|
||||||
getLogger().warn("GCAuth does not support automatic account creation. Please disable in the server's config.json or just ignore this warning.");
|
getLogger().warn("GCAuth does not support automatic account creation. Please disable in the server's config.json or just ignore this warning.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
Grasscutter.setAuthenticationSystem(new DefaultAuthentication());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package me.exzork.gcauth.handler;
|
package me.exzork.gcauth.handler;
|
||||||
|
|
||||||
import emu.grasscutter.auth.AuthenticationSystem;
|
import emu.grasscutter.auth.*;
|
||||||
import emu.grasscutter.auth.Authenticator;
|
|
||||||
import emu.grasscutter.auth.DefaultAuthenticators;
|
|
||||||
import emu.grasscutter.auth.ExternalAuthenticator;
|
|
||||||
import emu.grasscutter.server.http.objects.ComboTokenResJson;
|
import emu.grasscutter.server.http.objects.ComboTokenResJson;
|
||||||
import emu.grasscutter.server.http.objects.LoginResultJson;
|
import emu.grasscutter.server.http.objects.LoginResultJson;
|
||||||
|
|
||||||
@ -11,16 +8,16 @@ public class GCAuthAuthenticationHandler implements AuthenticationSystem {
|
|||||||
private final Authenticator<LoginResultJson> gcAuthAuthenticator = new GCAuthenticators.GCAuthAuthenticator();
|
private final Authenticator<LoginResultJson> gcAuthAuthenticator = new GCAuthenticators.GCAuthAuthenticator();
|
||||||
private final Authenticator<LoginResultJson> tokenAuthenticator = new DefaultAuthenticators.TokenAuthenticator();
|
private final Authenticator<LoginResultJson> tokenAuthenticator = new DefaultAuthenticators.TokenAuthenticator();
|
||||||
private final Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new DefaultAuthenticators.SessionKeyAuthenticator();
|
private final Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new DefaultAuthenticators.SessionKeyAuthenticator();
|
||||||
private final GCAuthExternalAuthenticator handler = new GCAuthExternalAuthenticator();
|
private final GCAuthExternalAuthenticator externalAuthenticator = new GCAuthExternalAuthenticator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createAccount(String username, String password) {
|
public void createAccount(String username, String password) {
|
||||||
|
// Unhandled.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resetPassword(String s) {
|
public void resetPassword(String username) {
|
||||||
|
// Unhandled.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,6 +42,6 @@ public class GCAuthAuthenticationHandler implements AuthenticationSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExternalAuthenticator getExternalAuthenticator() {
|
public ExternalAuthenticator getExternalAuthenticator() {
|
||||||
return handler;
|
return externalAuthenticator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import emu.grasscutter.auth.AuthenticationSystem;
|
|||||||
import emu.grasscutter.auth.ExternalAuthenticator;
|
import emu.grasscutter.auth.ExternalAuthenticator;
|
||||||
import emu.grasscutter.database.DatabaseHelper;
|
import emu.grasscutter.database.DatabaseHelper;
|
||||||
import emu.grasscutter.game.Account;
|
import emu.grasscutter.game.Account;
|
||||||
|
import express.http.Response;
|
||||||
import me.exzork.gcauth.GCAuth;
|
import me.exzork.gcauth.GCAuth;
|
||||||
import me.exzork.gcauth.json.AuthResponseJson;
|
import me.exzork.gcauth.json.AuthResponseJson;
|
||||||
import me.exzork.gcauth.json.ChangePasswordAccount;
|
import me.exzork.gcauth.json.ChangePasswordAccount;
|
||||||
@ -17,8 +18,11 @@ public class GCAuthExternalAuthenticator implements ExternalAuthenticator {
|
|||||||
@Override
|
@Override
|
||||||
public void handleLogin(AuthenticationSystem.AuthenticationRequest authenticationRequest) {
|
public void handleLogin(AuthenticationSystem.AuthenticationRequest authenticationRequest) {
|
||||||
AuthResponseJson authResponse = new AuthResponseJson();
|
AuthResponseJson authResponse = new AuthResponseJson();
|
||||||
|
Response response = authenticationRequest.getResponse();
|
||||||
|
assert response != null; // This should never be null.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String requestBody = authenticationRequest.getRequest().ctx().body();
|
String requestBody = response.ctx().body();
|
||||||
if (requestBody.isEmpty()) {
|
if (requestBody.isEmpty()) {
|
||||||
authResponse.success = false;
|
authResponse.success = false;
|
||||||
authResponse.message = "EMPTY_BODY"; // ENG = "No data was sent with the request"
|
authResponse.message = "EMPTY_BODY"; // ENG = "No data was sent with the request"
|
||||||
@ -55,15 +59,18 @@ public class GCAuthExternalAuthenticator implements ExternalAuthenticator {
|
|||||||
Grasscutter.getLogger().error("[Dispatch] An error occurred while a user was logging in.");
|
Grasscutter.getLogger().error("[Dispatch] An error occurred while a user was logging in.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
authenticationRequest.getResponse().send(authResponse);
|
response.send(authResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleAccountCreation(AuthenticationSystem.AuthenticationRequest authenticationRequest) {
|
public void handleAccountCreation(AuthenticationSystem.AuthenticationRequest authenticationRequest) {
|
||||||
AuthResponseJson authResponse = new AuthResponseJson();
|
AuthResponseJson authResponse = new AuthResponseJson();
|
||||||
|
Response response = authenticationRequest.getResponse();
|
||||||
|
assert response != null; // This should never be null.
|
||||||
|
|
||||||
Account account = null;
|
Account account = null;
|
||||||
try {
|
try {
|
||||||
String requestBody = authenticationRequest.getRequest().ctx().body();
|
String requestBody = response.ctx().body();
|
||||||
if (requestBody.isEmpty()) {
|
if (requestBody.isEmpty()) {
|
||||||
authResponse.success = false;
|
authResponse.success = false;
|
||||||
authResponse.message = "EMPTY_BODY"; // ENG = "No data was sent with the request"
|
authResponse.message = "EMPTY_BODY"; // ENG = "No data was sent with the request"
|
||||||
@ -129,14 +136,17 @@ public class GCAuthExternalAuthenticator implements ExternalAuthenticator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
authenticationRequest.getResponse().send(authResponse);
|
response.send(authResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePasswordReset(AuthenticationSystem.AuthenticationRequest authenticationRequest) {
|
public void handlePasswordReset(AuthenticationSystem.AuthenticationRequest authenticationRequest) {
|
||||||
AuthResponseJson authResponse = new AuthResponseJson();
|
AuthResponseJson authResponse = new AuthResponseJson();
|
||||||
|
Response response = authenticationRequest.getResponse();
|
||||||
|
assert response != null; // This should never be null.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String requestBody = authenticationRequest.getRequest().ctx().body();
|
String requestBody = response.ctx().body();
|
||||||
if (requestBody.isEmpty()) {
|
if (requestBody.isEmpty()) {
|
||||||
authResponse.success = false;
|
authResponse.success = false;
|
||||||
authResponse.message = "EMPTY_BODY"; // ENG = "No data was sent with the request"
|
authResponse.message = "EMPTY_BODY"; // ENG = "No data was sent with the request"
|
||||||
@ -182,7 +192,6 @@ public class GCAuthExternalAuthenticator implements ExternalAuthenticator {
|
|||||||
Grasscutter.getLogger().error("[Dispatch] Error while changing user password.");
|
Grasscutter.getLogger().error("[Dispatch] Error while changing user password.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
response.send(authResponse);
|
||||||
authenticationRequest.getResponse().send(authResponse);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package me.exzork.gcauth.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.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;
|
||||||
import me.exzork.gcauth.utils.Authentication;
|
import me.exzork.gcauth.utils.Authentication;
|
||||||
@ -17,7 +16,8 @@ public class GCAuthenticators {
|
|||||||
var response = new LoginResultJson();
|
var response = new LoginResultJson();
|
||||||
|
|
||||||
var requestData = authenticationRequest.getPasswordRequest();
|
var requestData = authenticationRequest.getPasswordRequest();
|
||||||
assert requestData != null;
|
assert requestData != null; // This should never be null.
|
||||||
|
|
||||||
Account account = Authentication.getAccountByOneTimeToken(requestData.account);
|
Account account = Authentication.getAccountByOneTimeToken(requestData.account);
|
||||||
if(account == null) {
|
if(account == null) {
|
||||||
Grasscutter.getLogger().info("[GCAuth] Client " + requestData.account + " tried to login with invalid one time token.");
|
Grasscutter.getLogger().info("[GCAuth] Client " + requestData.account + " tried to login with invalid one time token.");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "GCAuth",
|
"name": "GCAuth",
|
||||||
"description": "GCAuth is a plugin that allows you to implement authentication for your server.",
|
"description": "GCAuth is a plugin that allows you to implement authentication for your server.",
|
||||||
"version": "1.0.0",
|
"version": "2.2.0",
|
||||||
"author": ["ExZork"],
|
"author": ["ExZork"],
|
||||||
"mainClass": "me.exzork.gcauth.GCAuth"
|
"mainClass": "me.exzork.gcauth.GCAuth"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user