diff --git a/mall-auth/src/main/java/com/macro/mall/auth/controller/AuthController.java b/mall-auth/src/main/java/com/macro/mall/auth/controller/AuthController.java index 3aa8865..be54082 100644 --- a/mall-auth/src/main/java/com/macro/mall/auth/controller/AuthController.java +++ b/mall-auth/src/main/java/com/macro/mall/auth/controller/AuthController.java @@ -4,20 +4,16 @@ import com.macro.mall.auth.domain.Oauth2TokenDto; import com.macro.mall.common.api.CommonResult; import com.macro.mall.common.constant.AuthConstant; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint; import org.springframework.web.HttpRequestMethodNotSupportedException; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import springfox.documentation.annotations.ApiIgnore; +import org.springframework.web.bind.annotation.*; -import java.security.Principal; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; import java.util.Map; /** @@ -33,17 +29,22 @@ public class AuthController { private TokenEndpoint tokenEndpoint; @ApiOperation("Oauth2获取token") - @ApiImplicitParams({ - @ApiImplicitParam(name = "grant_type", value = "授权模式", required = true), - @ApiImplicitParam(name = "client_id", value = "Oauth2客户端ID", required = true), - @ApiImplicitParam(name = "client_secret", value = "Oauth2客户端秘钥", required = true), - @ApiImplicitParam(name = "refresh_token", value = "刷新token"), - @ApiImplicitParam(name = "username", value = "登录用户名"), - @ApiImplicitParam(name = "password", value = "登录密码") - }) @RequestMapping(value = "/token", method = RequestMethod.POST) - public CommonResult postAccessToken(@ApiIgnore Principal principal, @ApiIgnore @RequestParam Map parameters) throws HttpRequestMethodNotSupportedException { - OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody(); + public CommonResult postAccessToken(HttpServletRequest request, + @ApiParam("授权模式") @RequestParam String grant_type, + @ApiParam("Oauth2客户端ID") @RequestParam String client_id, + @ApiParam("Oauth2客户端秘钥") @RequestParam String client_secret, + @ApiParam("刷新token") @RequestParam(required = false) String refresh_token, + @ApiParam("登录用户名") @RequestParam(required = false) String username, + @ApiParam("登录密码") @RequestParam(required = false) String password) throws HttpRequestMethodNotSupportedException { + Map parameters = new HashMap<>(); + parameters.put("grant_type",grant_type); + parameters.put("client_id",client_id); + parameters.put("client_secret",client_secret); + parameters.putIfAbsent("refresh_token",refresh_token); + parameters.putIfAbsent("username",username); + parameters.putIfAbsent("password",password); + OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(request.getUserPrincipal(), parameters).getBody(); Oauth2TokenDto oauth2TokenDto = Oauth2TokenDto.builder() .token(oAuth2AccessToken.getValue()) .refreshToken(oAuth2AccessToken.getRefreshToken().getValue())