diff --git a/src/main/kotlin/com/hero/alignlab/client/kakao/KakaoOAuthService.kt b/src/main/kotlin/com/hero/alignlab/client/kakao/KakaoOAuthService.kt index a22422c..83938cd 100644 --- a/src/main/kotlin/com/hero/alignlab/client/kakao/KakaoOAuthService.kt +++ b/src/main/kotlin/com/hero/alignlab/client/kakao/KakaoOAuthService.kt @@ -13,6 +13,10 @@ class KakaoOAuthService( private val kaKaoOAuthClient: KaKaoOAuthClient, private val config: KakaoOAuthClientConfig.Config ) { + suspend fun getOAuthLoginLinkDev(): String { + return config.url + "?client_id=${config.restApiKey}&redirect_uri=${config.redirectUrl}&response_type=code" + } + suspend fun getOAuthAuthorizeCode(redirectUrl: String? = null) { withContext(Dispatchers.IO) { kaKaoOAuthClient.getOAuthAuthorizeCode(redirectUrl) diff --git a/src/main/kotlin/com/hero/alignlab/client/kakao/config/KakaoOAuthClientConfig.kt b/src/main/kotlin/com/hero/alignlab/client/kakao/config/KakaoOAuthClientConfig.kt index 796bd6a..9d781e4 100644 --- a/src/main/kotlin/com/hero/alignlab/client/kakao/config/KakaoOAuthClientConfig.kt +++ b/src/main/kotlin/com/hero/alignlab/client/kakao/config/KakaoOAuthClientConfig.kt @@ -46,7 +46,5 @@ class KakaoOAuthClientConfig { var clientSecretCode: String = "", @field:NotBlank var redirectUrl: String = "", - @field:NotBlank - var devRedirectUrl: String = "", ) } diff --git a/src/main/kotlin/com/hero/alignlab/domain/dev/application/DevOAuthService.kt b/src/main/kotlin/com/hero/alignlab/domain/dev/application/DevOAuthService.kt index a59382f..f678dec 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/dev/application/DevOAuthService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/dev/application/DevOAuthService.kt @@ -4,10 +4,7 @@ import com.hero.alignlab.client.kakao.KakaoOAuthService import com.hero.alignlab.client.kakao.config.KakaoOAuthClientConfig import com.hero.alignlab.client.kakao.model.response.GenerateKakaoOAuthTokenResponse import com.hero.alignlab.domain.auth.model.OAuthProvider -import com.hero.alignlab.domain.auth.model.request.OAuthAuthorizedRequest -import com.hero.alignlab.domain.dev.model.request.DevRedirectedRequest import com.hero.alignlab.domain.dev.model.response.DevOAuthCodeResponse -import com.hero.alignlab.domain.dev.model.response.DevRedirectedResponse import io.github.oshai.kotlinlogging.KotlinLogging import org.springframework.stereotype.Service @@ -19,31 +16,16 @@ class DevOAuthService( private val logger = KotlinLogging.logger { } suspend fun getOAuthAuthorizeCode(provider: OAuthProvider): DevOAuthCodeResponse { - when (provider) { - OAuthProvider.kakao -> kakaoOAuthService.getOAuthAuthorizeCode(config.devRedirectUrl) + val url = when (provider) { + OAuthProvider.kakao -> kakaoOAuthService.getOAuthLoginLinkDev() } - return DevOAuthCodeResponse(provider) + return DevOAuthCodeResponse(provider, url) } - fun redirectTest( - provider: OAuthProvider, - request: DevRedirectedRequest - ): DevRedirectedResponse { - logger.info { "redirect test provider: $provider request: $request" } - - return DevRedirectedResponse( - provider = provider, - requestParams = request, - ) - } - - suspend fun resolveOAuth( - provider: OAuthProvider, - request: OAuthAuthorizedRequest - ): GenerateKakaoOAuthTokenResponse { + suspend fun resolveOAuth(provider: OAuthProvider, code: String): GenerateKakaoOAuthTokenResponse { return when (provider) { - OAuthProvider.kakao -> kakaoOAuthService.generateOAuthToken(request.code, config.devRedirectUrl) + OAuthProvider.kakao -> kakaoOAuthService.generateOAuthToken(code, config.redirectUrl) } } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/dev/model/response/DevOAuthCodeResponse.kt b/src/main/kotlin/com/hero/alignlab/domain/dev/model/response/DevOAuthCodeResponse.kt index 8de93ad..27c3c0f 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/dev/model/response/DevOAuthCodeResponse.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/dev/model/response/DevOAuthCodeResponse.kt @@ -4,4 +4,5 @@ import com.hero.alignlab.domain.auth.model.OAuthProvider data class DevOAuthCodeResponse( val provider: OAuthProvider, + val authorizedUrl: String, ) diff --git a/src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevOAuthResource.kt b/src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevOAuthResource.kt index f0e21d5..f0ff982 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevOAuthResource.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevOAuthResource.kt @@ -2,12 +2,9 @@ package com.hero.alignlab.domain.dev.resource import com.hero.alignlab.common.extension.wrapOk import com.hero.alignlab.domain.auth.model.OAuthProvider -import com.hero.alignlab.domain.auth.model.request.OAuthAuthorizedRequest import com.hero.alignlab.domain.dev.application.DevOAuthService -import com.hero.alignlab.domain.dev.model.request.DevRedirectedRequest import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag -import org.springdoc.core.annotations.ParameterObject import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -18,22 +15,15 @@ class DevOAuthResource( private val devOAuthService: DevOAuthService, ) { @Operation(summary = "인가 코드 받기") - @PostMapping("/api/dev/v1/oauth/{provider}/authorize") + @GetMapping("/api/dev/v1/oauth/{provider}/authorize") suspend fun getDevOAuthAuthorizeCode( @PathVariable provider: OAuthProvider, ) = devOAuthService.getOAuthAuthorizeCode(provider).wrapOk() - @Operation(summary = "OAuth Redirect Test") - @GetMapping("/api/dev/v1/oauth/{provider}/authorize/redirected") - suspend fun redirectedDevOAuthAuthorizeCode( - @PathVariable provider: OAuthProvider, - @ParameterObject request: DevRedirectedRequest, - ) = devOAuthService.redirectTest(provider, request).wrapOk() - @Operation(summary = "OAuth Token Generate") - @PostMapping("/api/dev/v1/oauth/{provider}/token") + @GetMapping("/api/dev/v1/oauth/{provider}/token") suspend fun redirectedDevOAuthAuthorizeCode( @PathVariable provider: OAuthProvider, - @RequestBody request: OAuthAuthorizedRequest, - ) = devOAuthService.resolveOAuth(provider, request).wrapOk() + @RequestParam code: String, + ) = devOAuthService.resolveOAuth(provider, code).wrapOk() } diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 65b10ca..ed9cc5b 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -53,8 +53,7 @@ oauth: rest-api-key: client-secret-code: # redirect url for get OAuth Authorize Code - redirect-url: http://localhost:3000 - dev-redirect-url: https://api.alignlab.site/api/dev/v1/oauth/kakao/authorize/redirected + redirect-url: https://api.alignlab.site/api/dev/v1/oauth/kakao/token encrypt: key: