优化OAuth2.0

This commit is contained in:
zhou-hao
2017-12-05 22:31:30 +08:00
parent 7fac9f51ba
commit 56f70f90d6
4 changed files with 15 additions and 2 deletions

View File

@@ -19,9 +19,11 @@
package org.hswebframework.web.authorization.oauth2.client.request;
/**
* @author zhouhao
*/
@FunctionalInterface
public interface ReTry {
void doReTry();
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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];