zhou-hao 7 gadi atpakaļ
vecāks
revīzija
56f70f90d6

+ 2 - 0
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/ReTry.java

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

+ 8 - 0
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/SimpleOAuth2Request.java

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

+ 1 - 2
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/request/SimpleOAuth2Response.java

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

+ 4 - 0
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/java/org/hswebframework/web/oauth2/authorization/OAuth2UserTokenParser.java

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