Kaynağa Gözat

优化swagger

zhou-hao 7 yıl önce
ebeveyn
işleme
8717177591

+ 1 - 1
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2AuthorizeController.java

@@ -77,7 +77,7 @@ public class OAuth2AuthorizeController {
 
 
     @GetMapping(params = "response_type=token")
-    @ApiOperation(value = "implicit方式授权", tags = "OAuth2.0-申请token")
+    @ApiOperation(value = "implicit方式申请token", tags = "OAuth2.0-服务-申请token")
     @ApiImplicitParam(paramType = "query",name =  OAuth2Constants.client_id,required = true)
     public ImplicitAccessTokenModel authorizeByImplicit(
             @RequestParam(value = "redirect_uri") String redirect_uri,

+ 7 - 0
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ClientConfigController.java

@@ -3,6 +3,7 @@ package org.hswebframework.web.authorization.oauth2.controller;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.hswebframework.web.authorization.Authentication;
 import org.hswebframework.web.authorization.Permission;
 import org.hswebframework.web.authorization.annotation.Authorize;
 import org.hswebframework.web.authorization.oauth2.server.client.OAuth2Client;
@@ -50,6 +51,12 @@ public class OAuth2ClientConfigController {
     @Authorize(action = Permission.ACTION_UPDATE)
     @ApiOperation(value = "保存客户端", notes = "如果客户端不存在则自动新增")
     public ResponseMessage<OAuth2Client> saveOrUpdate(@RequestBody OAuth2ClientEntity clientEntity) {
+        Authentication authentication = Authentication.current().orElse(null);
+
+        if (null != authentication) {
+            clientEntity.setCreatorId(authentication.getUser().getId());
+        }
+        clientEntity.setCreateTimeNow();
         return ResponseMessage.ok(repository.save(clientEntity));
     }
 

+ 1 - 0
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2TokenController.java

@@ -58,6 +58,7 @@ public class OAuth2TokenController {
                     @ApiImplicitParam(paramType = "query", name = OAuth2Constants.client_id,required = true),
                     @ApiImplicitParam(paramType = "query", name = OAuth2Constants.client_secret),
                     @ApiImplicitParam(paramType = "query", name = OAuth2Constants.refresh_token),
+                    @ApiImplicitParam(paramType = "query", name = OAuth2Constants.redirect_uri),
                     @ApiImplicitParam(paramType = "query", name = OAuth2Constants.code),
                     @ApiImplicitParam(paramType = "query", name = OAuth2Constants.scope, example = "user-info:get,share:add"),
                     @ApiImplicitParam(paramType = "header", name = OAuth2Constants.authorization, example = "Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW")

+ 8 - 3
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2UserInfoController.java

@@ -20,6 +20,7 @@ package org.hswebframework.web.authorization.oauth2.controller;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.hswebframework.web.NotFoundException;
 import org.hswebframework.web.authorization.Authentication;
 import org.hswebframework.web.authorization.AuthenticationHolder;
 import org.hswebframework.web.authorization.exception.AccessDenyException;
@@ -64,10 +65,14 @@ public class OAuth2UserInfoController {
         if (null == auth2AccessEntity) {
             throw new GrantTokenException(ErrorType.EXPIRED_TOKEN);
         }
-        if (auth2AccessEntity.getScope() == null || !auth2AccessEntity.getScope().contains("user-info")) {
-            throw new GrantTokenException(ErrorType.UNSUPPORTED_GRANT_TYPE);
+        if (auth2AccessEntity.getScope() == null ||(!auth2AccessEntity.getScope().contains("*")&&!auth2AccessEntity.getScope().contains("user:get"))) {
+            throw new GrantTokenException(ErrorType.UNAUTHORIZED_CLIENT);
         }
-        return ResponseMessage.ok(AuthenticationHolder.get(userId));
+        Authentication info=  AuthenticationHolder.get(userId);
+        if(info==null){
+            throw new NotFoundException("user:"+userId+" not found");
+        }
+        return ResponseMessage.ok(info);
     }
 
 }