mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-30 09:32:52 +00:00
[BREAKING] Refactor OAuth handler
This commit is contained in:
parent
141b1913cb
commit
16846b46df
@ -131,16 +131,4 @@ public interface AuthenticationSystem {
|
||||
return AuthenticationRequest.builder().request(request)
|
||||
.response(response).build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates an authentication request from a {@link Response} object.
|
||||
* @param request The Express request.
|
||||
* @param jsonData The JSON data.
|
||||
* @return An authentication request.
|
||||
*/
|
||||
static AuthenticationRequest fromOAuthRequest(Request request, Response response) {
|
||||
return AuthenticationRequest.builder().request(request)
|
||||
.response(response).build();
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,22 @@ public interface OAuthAuthenticator {
|
||||
void handleLogin(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* Called when an client requests to redirect to login page.
|
||||
* Called when a client requests to redirect to login page.
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void handleDesktopRedirection(AuthenticationRequest request);
|
||||
void handleMobileRedirection(AuthenticationRequest request);
|
||||
void handleRedirection(AuthenticationRequest request, ClientType clientType);
|
||||
|
||||
/**
|
||||
* Called when an OAuth login requests callback.
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void handleTokenProcess(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* The type of the client.
|
||||
* Used for handling redirection.
|
||||
*/
|
||||
enum ClientType {
|
||||
DESKTOP, MOBILE
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package emu.grasscutter.server.http.dispatch;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.auth.AuthenticationSystem;
|
||||
import emu.grasscutter.auth.OAuthAuthenticator;
|
||||
import emu.grasscutter.auth.OAuthAuthenticator.ClientType;
|
||||
import emu.grasscutter.server.http.Router;
|
||||
import emu.grasscutter.server.http.objects.*;
|
||||
import emu.grasscutter.server.http.objects.ComboTokenReqJson.LoginTokenData;
|
||||
@ -34,13 +36,15 @@ public final class DispatchHandler implements Router {
|
||||
express.post("/authentication/change_password", (request, response) -> Grasscutter.getAuthenticationSystem().getExternalAuthenticator()
|
||||
.handlePasswordReset(AuthenticationSystem.fromExternalRequest(request, response)));
|
||||
|
||||
// OAuth login
|
||||
express.post("/hk4e_global/mdk/shield/api/loginByThirdparty", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator().handleLogin(AuthenticationSystem.fromOAuthRequest(request, response)));
|
||||
// OAuth querystring convert redirection
|
||||
express.get("/authentication/openid/redirect", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator().handleTokenProcess(AuthenticationSystem.fromOAuthRequest(request, response)));
|
||||
// OAuth redirection
|
||||
express.get("/Api/twitter_login", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator().handleDesktopRedirection(AuthenticationSystem.fromOAuthRequest(request, response)));
|
||||
express.get("/sdkTwitterLogin.html", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator().handleMobileRedirection(AuthenticationSystem.fromOAuthRequest(request, response)));
|
||||
// External login (from OAuth2).
|
||||
express.post("/hk4e_global/mdk/shield/api/loginByThirdparty", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator()
|
||||
.handleLogin(AuthenticationSystem.fromExternalRequest(request, response)));
|
||||
express.get("/authentication/openid/redirect", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator()
|
||||
.handleTokenProcess(AuthenticationSystem.fromExternalRequest(request, response)));
|
||||
express.get("/Api/twitter_login", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator()
|
||||
.handleRedirection(AuthenticationSystem.fromExternalRequest(request, response), ClientType.DESKTOP));
|
||||
express.get("/sdkTwitterLogin.html", (request, response) -> Grasscutter.getAuthenticationSystem().getOAuthAuthenticator()
|
||||
.handleRedirection(AuthenticationSystem.fromExternalRequest(request, response), ClientType.MOBILE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user