package com.iailab.module.system.api.oauth2; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; import com.iailab.module.system.api.oauth2.dto.OAuth2AccessTokenCreateReqDTO; import com.iailab.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO; import com.iailab.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import com.iailab.module.system.service.oauth2.OAuth2TokenService; import io.swagger.v3.oas.annotations.Operation; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import static com.iailab.framework.common.pojo.CommonResult.success; @RestController // 提供 RESTful API 接口,给 Feign 调用 @Validated public class OAuth2TokenApiImpl implements OAuth2TokenApi { @Resource private OAuth2TokenService oauth2TokenService; @Override public CommonResult createAccessToken(OAuth2AccessTokenCreateReqDTO reqDTO) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken( reqDTO.getUserId(), reqDTO.getUserType(), reqDTO.getClientId(), reqDTO.getScopes()); return success(BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class)); } @Override public CommonResult checkAccessToken(String accessToken) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.checkAccessToken(accessToken); return success(BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenCheckRespDTO.class)); } @Override public CommonResult removeAccessToken(String accessToken) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.removeAccessToken(accessToken); return success(BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class)); } @Override public CommonResult refreshAccessToken(String refreshToken, String clientId) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, clientId); return success(BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class)); } }