Skip to content

Commit

Permalink
fix: dev oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Jul 29, 2024
1 parent 9a27f6e commit 2214dda
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ class KakaoOAuthClientConfig {
var clientSecretCode: String = "",
@field:NotBlank
var redirectUrl: String = "",
@field:NotBlank
var devRedirectUrl: String = "",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import com.hero.alignlab.domain.auth.model.OAuthProvider

data class DevOAuthCodeResponse(
val provider: OAuthProvider,
val authorizedUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand All @@ -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()
}
3 changes: 1 addition & 2 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2214dda

Please sign in to comment.