增加令牌刷新逻辑

增加演示模式的开关
This commit is contained in:
YunaiV
2020-08-26 20:47:46 +08:00
parent 54325da259
commit e0ab6b8462
10 changed files with 77 additions and 17 deletions

View File

@@ -10,4 +10,10 @@ Content-Type: application/x-www-form-urlencoded
mobile=15601691300&scene=1
### /passport/refresh-token
POST {{user-api-base-url}}/passport/refresh-token
Content-Type: application/x-www-form-urlencoded
refreshToken=77abd74e84e34cfc8aba9625317a14a3
###

View File

@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@@ -44,4 +45,12 @@ public class PassportController {
return success(true);
}
@PostMapping("/refresh-token")
@ApiOperation("刷新令牌")
@RequiresNone
public CommonResult<PassportAccessTokenRespVO> refreshToken(@RequestParam("refreshToken") String refreshToken,
HttpServletRequest request) {
return success(passportManager.refreshToken(refreshToken, HttpUtil.getIp(request)));
}
}

View File

@@ -5,6 +5,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RefreshAccessTokenReqDTO;
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
import cn.iocoder.mall.userservice.rpc.sms.UserSmsCodeRpc;
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
@@ -50,4 +51,11 @@ public class PassportManager {
sendSmsCodeResult.checkError();
}
public PassportAccessTokenRespVO refreshToken(String refreshToken, String ip) {
CommonResult<OAuth2AccessTokenRespDTO> refreshAccessTokenResult = oauth2Rpc.refreshAccessToken(
new OAuth2RefreshAccessTokenReqDTO().setRefreshToken(refreshToken).setCreateIp(ip));
refreshAccessTokenResult.checkError();
return PassportConvert.INSTANCE.convert(refreshAccessTokenResult.getData());
}
}