diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml
index 8d7315028..78757a88c 100644
--- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml
@@ -48,7 +48,22 @@
org.hswebframework.web
hsweb-commons-utils
- 3.0-SNAPSHOT
+ ${project.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+ true
+
+
+ org.springframework
+ spring-webmvc
+
+
+ org.hswebframework.web
+ hsweb-commons-controller
+ ${project.version}
\ No newline at end of file
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/OAuth2ServerAutoConfiguration.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/OAuth2ServerAutoConfiguration.java
new file mode 100644
index 000000000..4420bbbe3
--- /dev/null
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/OAuth2ServerAutoConfiguration.java
@@ -0,0 +1,32 @@
+package org.hswebframework.web.authorization.oauth2.server;
+
+import org.hswebframework.web.authorization.oauth2.server.exception.GrantTokenException;
+import org.hswebframework.web.controller.message.ResponseMessage;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+@Configuration
+public class OAuth2ServerAutoConfiguration{
+
+ @Bean
+ public OAuth2ServerErrorControllerAdvice oAuth2ServerErrorControllerAdvice(){
+ return new OAuth2ServerErrorControllerAdvice();
+ }
+ /**
+ * @author zhouhao
+ */
+ @RestControllerAdvice
+ public static class OAuth2ServerErrorControllerAdvice {
+
+ @ExceptionHandler(GrantTokenException.class)
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ public ResponseMessage error(GrantTokenException e) {
+ return ResponseMessage.error(e.getErrorType().code(),e.getMessage())
+ .result(e.getErrorType().message());
+ }
+ }
+}
+
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/refresh/DefaultRefreshTokenGranter.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/refresh/DefaultRefreshTokenGranter.java
index d3b513fcd..3b615f48e 100644
--- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/refresh/DefaultRefreshTokenGranter.java
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/java/org/hswebframework/web/authorization/oauth2/server/support/refresh/DefaultRefreshTokenGranter.java
@@ -59,7 +59,7 @@ public class DefaultRefreshTokenGranter extends AbstractAuthorizationService imp
OAuth2AccessToken accessToken = accessTokenService.getTokenByRefreshToken(refreshToken);
if (accessToken == null) {
- throw new GrantTokenException(ILLEGAL_REFRESH_TOKEN);
+ throw new GrantTokenException(EXPIRED_REFRESH_TOKEN);
}
if (System.currentTimeMillis() - accessToken.getCreateTime() > refreshTokenTimeOut) {
throw new GrantTokenException(EXPIRED_REFRESH_TOKEN);
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/resources/META-INF/spring.factories b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/resources/META-INF/spring.factories
new file mode 100644
index 000000000..c9facd3ad
--- /dev/null
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,3 @@
+# Auto Configure
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.hswebframework.web.authorization.oauth2.server.OAuth2ServerAutoConfiguration
\ No newline at end of file
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml
index d0b4a4263..40ef86ec5 100644
--- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml
@@ -60,5 +60,10 @@
hsweb-expands-request
${hsweb.expands.version}
+
+ org.hswebframework.web
+ hsweb-commons-controller
+ ${project.version}
+
\ No newline at end of file
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/exception/OAuth2RequestException.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/exception/OAuth2RequestException.java
index 62ebe7216..d95236ec8 100644
--- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/exception/OAuth2RequestException.java
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/exception/OAuth2RequestException.java
@@ -21,6 +21,8 @@ package org.hswebframework.web.authorization.oauth2.client.exception;
import org.hswebframework.web.authorization.oauth2.client.response.OAuth2Response;
import org.hswebframework.web.oauth2.core.ErrorType;
+import java.io.PrintStream;
+
/**
* @author zhouhao
*/
@@ -35,6 +37,12 @@ public class OAuth2RequestException extends RuntimeException {
this.response = response;
}
+ public OAuth2RequestException(String message,ErrorType errorType, OAuth2Response response) {
+ super(message);
+ this.errorType = errorType;
+ this.response = response;
+ }
+
public ErrorType getErrorType() {
return errorType;
}
@@ -42,4 +50,5 @@ public class OAuth2RequestException extends RuntimeException {
public OAuth2Response getResponse() {
return response;
}
+
}
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/OAuth2Request.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/OAuth2Request.java
index b4ce103f3..7f2ac74d8 100644
--- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/OAuth2Request.java
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/OAuth2Request.java
@@ -29,6 +29,8 @@ import java.util.function.Consumer;
*/
public interface OAuth2Request {
+ OAuth2Request onRefreshTokenExpired(TokenExpiredCallBack refreshTokenExpiredCallBack);
+
OAuth2Request onTokenExpired(TokenExpiredCallBack callback);
/**
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/ReTry.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/ReTry.java
index d8ab58deb..db57d4db0 100644
--- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/ReTry.java
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/request/ReTry.java
@@ -20,8 +20,6 @@ package org.hswebframework.web.authorization.oauth2.client.request;
/**
- * TODO 完成注释
- *
* @author zhouhao
*/
public interface ReTry {
diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/provider/HswebResponseConvertSupport.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/provider/HswebResponseConvertSupport.java
index 49eb4ec8a..9b444e640 100644
--- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/provider/HswebResponseConvertSupport.java
+++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/provider/HswebResponseConvertSupport.java
@@ -19,16 +19,23 @@
package org.hswebframework.web.authorization.oauth2.client.simple.provider;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.parser.Feature;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.builder.AuthenticationBuilderFactory;
import org.hswebframework.web.authorization.oauth2.client.exception.OAuth2RequestException;
import org.hswebframework.web.authorization.oauth2.client.request.definition.ResponseConvertForProviderDefinition;
import org.hswebframework.web.authorization.oauth2.client.response.OAuth2Response;
+import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.oauth2.core.ErrorType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.Collection;
import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
/**
* @author zhouhao
@@ -37,30 +44,97 @@ public class HswebResponseConvertSupport implements ResponseConvertForProviderDe
private AuthenticationBuilderFactory authenticationBuilderFactory;
+ private static int responseMessageFieldSize = 4;
+
+ Function