mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-06-26 18:14:50 +08:00
Compare commits
No commits in common. "a0deb2c1f82b04fff87858c00d5bdfc867971ec8" and "141b1913cbfe1c9b7d2f8ac224e53f877790c7a2" have entirely different histories.
a0deb2c1f8
...
141b1913cb
@ -131,4 +131,16 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +215,12 @@ public final class DefaultAuthenticators {
|
||||
request.getResponse().send("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
|
||||
@Override public void handleRedirection(AuthenticationRequest request, ClientType type) {
|
||||
@Override public void handleDesktopRedirection(AuthenticationRequest request) {
|
||||
assert request.getResponse() != null;
|
||||
request.getResponse().send("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
|
||||
@Override public void handleMobileRedirection(AuthenticationRequest request) {
|
||||
assert request.getResponse() != null;
|
||||
request.getResponse().send("Authentication is not available with the default authentication method.");
|
||||
}
|
||||
|
@ -14,22 +14,15 @@ public interface OAuthAuthenticator {
|
||||
void handleLogin(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* Called when a client requests to redirect to login page.
|
||||
* Called when an client requests to redirect to login page.
|
||||
* @param request The authentication request.
|
||||
*/
|
||||
void handleRedirection(AuthenticationRequest request, ClientType clientType);
|
||||
void handleDesktopRedirection(AuthenticationRequest request);
|
||||
void handleMobileRedirection(AuthenticationRequest request);
|
||||
|
||||
/**
|
||||
* 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,8 +2,6 @@ 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;
|
||||
@ -36,15 +34,13 @@ public final class DispatchHandler implements Router {
|
||||
express.post("/authentication/change_password", (request, response) -> Grasscutter.getAuthenticationSystem().getExternalAuthenticator()
|
||||
.handlePasswordReset(AuthenticationSystem.fromExternalRequest(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));
|
||||
// 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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user