Commit c1deebfc authored by Quxl's avatar Quxl

x

parent d68cf3a3
...@@ -35,7 +35,7 @@ public interface OAuthApi { ...@@ -35,7 +35,7 @@ public interface OAuthApi {
final String OAUTH_TOKEN_SESSION = "OAUTH2_TOKEN_SESSION_KEY"; final String OAUTH_TOKEN_SESSION = "OAUTH2_TOKEN_SESSION_KEY";
default boolean isLogin() { default boolean isExistsOAuthToken() {
return getOAuthToken() != null; return getOAuthToken() != null;
} }
...@@ -88,9 +88,6 @@ public interface OAuthApi { ...@@ -88,9 +88,6 @@ public interface OAuthApi {
default void callback() { default void callback() {
try { try {
HttpServletRequest request = this.getHttpServletRequest(); HttpServletRequest request = this.getHttpServletRequest();
HttpSession session = request.getSession();
OAuthToken token = (OAuthToken)session.getAttribute(OAUTH_TOKEN_SESSION);
if(token == null) {
OAuthConfig config = this.getOAuthConfig(); OAuthConfig config = this.getOAuthConfig();
OAuthAuthzResponse oauthAuthzResponse = OAuthAuthzResponse.oauthCodeAuthzResponse(request); OAuthAuthzResponse oauthAuthzResponse = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
String code = oauthAuthzResponse.getCode(); String code = oauthAuthzResponse.getCode();
...@@ -108,11 +105,8 @@ public interface OAuthApi { ...@@ -108,11 +105,8 @@ public interface OAuthApi {
Long expiresIn = oAuthResponse.getExpiresIn(); Long expiresIn = oAuthResponse.getExpiresIn();
String idToken = oAuthResponse.getParam("id_token"); String idToken = oAuthResponse.getParam("id_token");
String tokenType = oAuthResponse.getTokenType(); String tokenType = oAuthResponse.getTokenType();
token = new OAuthToken(accessToken, refreshToken, idToken, tokenType, expiresIn); OAuthToken token = new OAuthToken(accessToken, refreshToken, idToken, tokenType, expiresIn);
session.setAttribute(OAUTH_TOKEN_SESSION, token); saveOAuthToken(token);
} else {
throw new OAuthApiException("OAuthToken already exists");
}
} catch (OAuthApiException e) { } catch (OAuthApiException e) {
throw e; throw e;
} catch (Throwable e) { } catch (Throwable e) {
...@@ -120,6 +114,12 @@ public interface OAuthApi { ...@@ -120,6 +114,12 @@ public interface OAuthApi {
} }
} }
default void saveOAuthToken(OAuthToken token) {
HttpServletRequest request = this.getHttpServletRequest();
HttpSession session = request.getSession();
session.setAttribute(OAUTH_TOKEN_SESSION, token);
}
default void removeOAuthToken() { default void removeOAuthToken() {
try { try {
HttpServletRequest request = this.getHttpServletRequest(); HttpServletRequest request = this.getHttpServletRequest();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment