Bläddra i källkod

add INVALID_TOKEN retry callback

zhouhao 7 år sedan
förälder
incheckning
f8c0521000

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

@@ -140,6 +140,13 @@ public class SimpleOAuth2Request implements OAuth2Request {
             });
         }
         if (null != refreshTokenExpiredCallBack) {
+            //判定token是否有效,无效的token将重新申请token
+            auth2Response.judgeError(ErrorType.INVALID_TOKEN,() -> {
+                //调用回调,并指定重试的操作(重新请求)
+                refreshTokenExpiredCallBack.call(() -> createNativeResponse(responseSupplier));
+                //返回重试后的response
+                return auth2Response;
+            });
             //判定refresh_token是否过期,过期后先执行回调进行操作如更新token,并尝试重新请求
             auth2Response.judgeError(ErrorType.EXPIRED_REFRESH_TOKEN,() -> {
                 //调用回调,并指定重试的操作(重新请求)

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

@@ -64,7 +64,8 @@ public class SimpleOAuth2Response implements OAuth2Response {
 
                 if (type == ifError) {
                     //重试后依然是相同的错误,可能是错误类型判断错误或者服务端的问题?
-                    logger.error("still error [{}], maybe judge error or auth server error! ",ifError);
+                    logger.error("still error [{}], maybe judge error or auth server error! response:{}"
+                            ,ifError,retryResponse.asString());
                 } else {
                     errorType = type;
                 }