mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-08 00:49:21 +08:00
优化OAuth2.0
This commit is contained in:
@@ -19,9 +19,11 @@
|
||||
package org.hswebframework.web.authorization.oauth2.client.request;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ReTry {
|
||||
void doReTry();
|
||||
}
|
||||
|
||||
@@ -154,6 +154,14 @@ public class SimpleOAuth2Request implements OAuth2Request {
|
||||
//返回重试后的response
|
||||
return auth2Response;
|
||||
});
|
||||
|
||||
//如果是invalid token 也将重新生成token
|
||||
auth2Response.judgeError(ErrorType.INVALID_TOKEN,() -> {
|
||||
//调用回调,并指定重试的操作(重新请求)
|
||||
refreshTokenExpiredCallBack.call(() -> createNativeResponse(responseSupplier));
|
||||
//返回重试后的response
|
||||
return auth2Response;
|
||||
});
|
||||
}
|
||||
return auth2Response;
|
||||
}
|
||||
|
||||
@@ -64,8 +64,7 @@ public class SimpleOAuth2Response implements OAuth2Response {
|
||||
|
||||
if (type == ifError) {
|
||||
//重试后依然是相同的错误,可能是错误类型判断错误或者服务端的问题?
|
||||
logger.error("still error [{}], maybe judge error or auth server error! response:{}"
|
||||
,ifError,retryResponse.asString());
|
||||
logger.error("still error [{}], maybe judge error or auth server error! {}",ifError,retryResponse,Thread.currentThread().getStackTrace());
|
||||
} else {
|
||||
errorType = type;
|
||||
}
|
||||
|
||||
@@ -28,10 +28,14 @@ public class OAuth2UserTokenParser implements UserTokenParser {
|
||||
|
||||
@Override
|
||||
public ParsedToken parseToken(HttpServletRequest request) {
|
||||
if (request.getRequestURI().contains("oauth2")&&request.getParameter(OAuth2Constants.grant_type) != null) {
|
||||
return null;
|
||||
}
|
||||
String accessToken = request.getHeader(OAuth2Constants.authorization);
|
||||
if (StringUtils.isEmpty(accessToken)) {
|
||||
accessToken = request.getParameter(OAuth2Constants.access_token);
|
||||
} else {
|
||||
|
||||
String[] arr = accessToken.split("[ ]");
|
||||
if (arr.length > 1) {
|
||||
accessToken = arr[1];
|
||||
|
||||
Reference in New Issue
Block a user