Skip to content

Commit

Permalink
feat:蓝盾APP Oauth2授权登录实现 #9353
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Sep 14, 2023
1 parent aa74605 commit d05a780
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.tencent.devops.openapi.api.apigw.v4

import com.tencent.devops.auth.pojo.Oauth2AccessTokenRequest
import com.tencent.devops.auth.pojo.vo.Oauth2AccessTokenVo
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE
import com.tencent.devops.common.api.auth.AUTH_HEADER_OAUTH2_CLIENT_ID
Expand Down Expand Up @@ -44,5 +43,5 @@ interface ApigwOauth2EndpointResourceV4 {
clientSecret: String,
@ApiParam("oauth2获取token请求报文体", required = true)
accessTokenRequest: Oauth2AccessTokenRequest
): Result<Oauth2AccessTokenVo?>
): Result<Any?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.tencent.devops.openapi.resources.apigw.v4

import com.tencent.devops.auth.api.oauth2.Oauth2ServiceEndpointResource
import com.tencent.devops.auth.pojo.Oauth2AccessTokenRequest
import com.tencent.devops.auth.pojo.vo.Oauth2AccessTokenVo
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.api.exception.RemoteServiceException
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.web.RestResource
Expand All @@ -21,16 +22,25 @@ class ApigwOauth2EndpointResourceV4Impl @Autowired constructor(
clientId: String,
clientSecret: String,
accessTokenRequest: Oauth2AccessTokenRequest
): Result<Oauth2AccessTokenVo?> {
): Result<Any?> {
logger.info("OPENAPI_OAUTH2_ACCESS_TOKEN_V4|$appCode|$clientId")
return client.get(Oauth2ServiceEndpointResource::class).getAccessToken(
clientId = clientId,
clientSecret = clientSecret,
accessTokenRequest = accessTokenRequest
)
return try {
client.get(Oauth2ServiceEndpointResource::class).getAccessToken(
clientId = clientId,
clientSecret = clientSecret,
accessTokenRequest = accessTokenRequest
)
} catch (ex: ErrorCodeException) {
Result(status = ex.errorCode.toInt(), message = ex.defaultMessage)
} catch (rex: RemoteServiceException) {
Result(status = rex.errorCode ?: REMOTE_EXCEPTION_CODE, message = rex.errorMessage)
} catch (ignore: Exception) {
throw ignore
}
}

companion object {
val logger = LoggerFactory.getLogger(ApigwOauth2EndpointResourceV4Impl::class.java)
private const val REMOTE_EXCEPTION_CODE = 500
}
}

0 comments on commit d05a780

Please sign in to comment.