mirror of
https://github.com/Xtao-Labs/GCAuth-OAuth.git
synced 2024-11-25 09:37:35 +00:00
🐛 Fix android cannot get username
This commit is contained in:
parent
7ad25381be
commit
a8dc9b9234
@ -10,7 +10,7 @@ sourceCompatibility = 17
|
||||
targetCompatibility = 17
|
||||
|
||||
group 'com.xtaolabs.gcauth_oauth'
|
||||
version '1.1.0'
|
||||
version '1.1.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -8,7 +8,7 @@ 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<LoginResultJson> tokenAuthenticator = new GCAuthenticators.TokenAuthenticator();
|
||||
private final Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new DefaultAuthenticators.SessionKeyAuthenticator();
|
||||
private final GCAuthExternalAuthenticator externalAuthenticator = new GCAuthExternalAuthenticator();
|
||||
|
||||
|
@ -3,15 +3,16 @@ package com.xtaolabs.gcauth_oauth.handler;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.auth.AuthenticationSystem;
|
||||
import emu.grasscutter.auth.Authenticator;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.server.http.objects.LoginResultJson;
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
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();
|
||||
@ -38,4 +39,49 @@ public class GCAuthenticators {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the authentication request from the game when using a registry token.
|
||||
*/
|
||||
public static class TokenAuthenticator implements Authenticator<LoginResultJson> {
|
||||
@Override
|
||||
public LoginResultJson authenticate(AuthenticationSystem.AuthenticationRequest request) {
|
||||
var response = new LoginResultJson();
|
||||
|
||||
var requestData = request.getTokenRequest();
|
||||
assert requestData != null;
|
||||
|
||||
boolean successfulLogin;
|
||||
String address = request.getRequest().ip();
|
||||
|
||||
// Log the attempt.
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.login_token_attempt", address));
|
||||
|
||||
// Get account from database.
|
||||
Account account = DatabaseHelper.getAccountById(requestData.uid);
|
||||
|
||||
// Check if account exists/token is valid.
|
||||
successfulLogin = account != null && account.getSessionKey().equals(requestData.token);
|
||||
|
||||
// Set response data.
|
||||
if(successfulLogin) {
|
||||
response.message = "OK";
|
||||
response.data.account.uid = account.getId();
|
||||
response.data.account.token = account.getSessionKey();
|
||||
response.data.account.email = account.getEmail();
|
||||
response.data.account.twitter_name = account.getUsername();
|
||||
|
||||
// Log the login.
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.login_token_success", address, requestData.uid));
|
||||
} else {
|
||||
response.retcode = -201;
|
||||
response.message = translate("messages.dispatch.account.account_cache_error");
|
||||
|
||||
// Log the failure.
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.login_token_error", address));
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "GCAuth_OAuth",
|
||||
"description": "The in-game login system for Grasscutter is based on oauth and GCAuth.",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"author": ["omg-xtao"],
|
||||
"mainClass": "com.xtaolabs.gcauth_oauth.GCAuth_OAuth"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user