Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
52c86afe
Commit
52c86afe
authored
May 27, 2022
by
KingRainbow44
Browse files
[BREAKING] Refactor OAuth handler
parent
243ad3ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/auth/AuthenticationSystem.java
View file @
52c86afe
...
@@ -131,16 +131,4 @@ public interface AuthenticationSystem {
...
@@ -131,16 +131,4 @@ public interface AuthenticationSystem {
return
AuthenticationRequest
.
builder
().
request
(
request
)
return
AuthenticationRequest
.
builder
().
request
(
request
)
.
response
(
response
).
build
();
.
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
();
}
}
}
src/main/java/emu/grasscutter/auth/OAuthAuthenticator.java
View file @
52c86afe
...
@@ -14,15 +14,22 @@ public interface OAuthAuthenticator {
...
@@ -14,15 +14,22 @@ public interface OAuthAuthenticator {
void
handleLogin
(
AuthenticationRequest
request
);
void
handleLogin
(
AuthenticationRequest
request
);
/**
/**
* Called when a
n
client requests to redirect to login page.
* Called when a client requests to redirect to login page.
* @param request The authentication request.
* @param request The authentication request.
*/
*/
void
handleDesktopRedirection
(
AuthenticationRequest
request
);
void
handleRedirection
(
AuthenticationRequest
request
,
ClientType
clientType
);
void
handleMobileRedirection
(
AuthenticationRequest
request
);
/**
/**
* Called when an OAuth login requests callback.
* Called when an OAuth login requests callback.
* @param request The authentication request.
* @param request The authentication request.
*/
*/
void
handleTokenProcess
(
AuthenticationRequest
request
);
void
handleTokenProcess
(
AuthenticationRequest
request
);
/**
* The type of the client.
* Used for handling redirection.
*/
enum
ClientType
{
DESKTOP
,
MOBILE
}
}
}
src/main/java/emu/grasscutter/server/http/dispatch/DispatchHandler.java
View file @
52c86afe
...
@@ -2,6 +2,8 @@ package emu.grasscutter.server.http.dispatch;
...
@@ -2,6 +2,8 @@ package emu.grasscutter.server.http.dispatch;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.auth.AuthenticationSystem
;
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.Router
;
import
emu.grasscutter.server.http.objects.*
;
import
emu.grasscutter.server.http.objects.*
;
import
emu.grasscutter.server.http.objects.ComboTokenReqJson.LoginTokenData
;
import
emu.grasscutter.server.http.objects.ComboTokenReqJson.LoginTokenData
;
...
@@ -34,13 +36,15 @@ public final class DispatchHandler implements Router {
...
@@ -34,13 +36,15 @@ public final class DispatchHandler implements Router {
express
.
post
(
"/authentication/change_password"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getExternalAuthenticator
()
express
.
post
(
"/authentication/change_password"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getExternalAuthenticator
()
.
handlePasswordReset
(
AuthenticationSystem
.
fromExternalRequest
(
request
,
response
)));
.
handlePasswordReset
(
AuthenticationSystem
.
fromExternalRequest
(
request
,
response
)));
// OAuth login
// External login (from OAuth2).
express
.
post
(
"/hk4e_global/mdk/shield/api/loginByThirdparty"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
().
handleLogin
(
AuthenticationSystem
.
fromOAuthRequest
(
request
,
response
)));
express
.
post
(
"/hk4e_global/mdk/shield/api/loginByThirdparty"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
()
// OAuth querystring convert redirection
.
handleLogin
(
AuthenticationSystem
.
fromExternalRequest
(
request
,
response
)));
express
.
get
(
"/authentication/openid/redirect"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
().
handleTokenProcess
(
AuthenticationSystem
.
fromOAuthRequest
(
request
,
response
)));
express
.
get
(
"/authentication/openid/redirect"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
()
// OAuth redirection
.
handleTokenProcess
(
AuthenticationSystem
.
fromExternalRequest
(
request
,
response
)));
express
.
get
(
"/Api/twitter_login"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
().
handleDesktopRedirection
(
AuthenticationSystem
.
fromOAuthRequest
(
request
,
response
)));
express
.
get
(
"/Api/twitter_login"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
()
express
.
get
(
"/sdkTwitterLogin.html"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
().
handleMobileRedirection
(
AuthenticationSystem
.
fromOAuthRequest
(
request
,
response
)));
.
handleRedirection
(
AuthenticationSystem
.
fromExternalRequest
(
request
,
response
),
ClientType
.
DESKTOP
));
express
.
get
(
"/sdkTwitterLogin.html"
,
(
request
,
response
)
->
Grasscutter
.
getAuthenticationSystem
().
getOAuthAuthenticator
()
.
handleRedirection
(
AuthenticationSystem
.
fromExternalRequest
(
request
,
response
),
ClientType
.
MOBILE
));
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment