From 7ecf871b8c3823b1a4d69655793a0985cd726f7c Mon Sep 17 00:00:00 2001 From: anjeongkyun Date: Wed, 15 Nov 2023 01:57:50 +0900 Subject: [PATCH] =?UTF-8?q?GetOAuthInfoQueryProcessor=EC=97=90=20KakaoApiC?= =?UTF-8?q?lient=20=EC=9D=98=EC=A1=B4=EC=84=B1=EC=9D=84=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/tagwonder/configs/UseCaseContext.kt | 16 ++++++++++++++-- .../main/kotlin/org/tagwonder/KakaoApiClient.kt | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/api/src/main/kotlin/org/tagwonder/configs/UseCaseContext.kt b/api/src/main/kotlin/org/tagwonder/configs/UseCaseContext.kt index 2796ddd..aae8f0c 100644 --- a/api/src/main/kotlin/org/tagwonder/configs/UseCaseContext.kt +++ b/api/src/main/kotlin/org/tagwonder/configs/UseCaseContext.kt @@ -1,8 +1,11 @@ package org.tagwonder.configs +import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.tagwonder.KakaoApiClient import org.tagwonder.jwt.AuthTokenGenerator +import org.tagwonder.oAuth.OAuthProvider import org.tagwonder.repositories.IMemberRepository import org.tagwonder.repositories.ITagRepository import org.tagwonder.usecases.commands.CreateTagsCommandExecutor @@ -44,9 +47,18 @@ open class UseCaseContext { //TODO(refactor): processor에서 제거하기 @Bean open fun getOAuthInfoQueryProcessor( - tagRepository: ITagRepository + tagRepository: ITagRepository, + @Value("\${oauth.kakao.url.protocol}") protocol: String, + @Value("\${oauth.kakao.url.auth-host}") authHost: String, + @Value("\${oauth.kakao.url.api-host}") apiHost: String, + @Value("\${oauth.kakao.client-id}") clientId: String, + @Value("\${oauth.kakao.authorization-grant-type}") grantType: String, ): GetOAuthInfoQueryProcessor { - return GetOAuthInfoQueryProcessor(mapOf()) + return GetOAuthInfoQueryProcessor( + mapOf( + OAuthProvider.KAKAO to KakaoApiClient(protocol, authHost, apiHost, clientId, grantType) + ) + ) } @Bean diff --git a/gateway/src/main/kotlin/org/tagwonder/KakaoApiClient.kt b/gateway/src/main/kotlin/org/tagwonder/KakaoApiClient.kt index c5124ee..5fe05f9 100644 --- a/gateway/src/main/kotlin/org/tagwonder/KakaoApiClient.kt +++ b/gateway/src/main/kotlin/org/tagwonder/KakaoApiClient.kt @@ -20,7 +20,8 @@ import java.util.concurrent.TimeUnit data class KakaoApiClient( private val protocol: String, - private val host: String, + private val authHost: String, + private val apiHost: String, private val clientId: String, private val grantType: String ): OAuthApiClient { @@ -46,7 +47,6 @@ data class KakaoApiClient( private fun makeBaseUrl(): String { return UriComponentsBuilder.newInstance() .scheme(protocol) - .host(host) .build() .toUriString() } @@ -57,7 +57,7 @@ data class KakaoApiClient( override fun requestAccessToken(request: ISignInOAuth): String { return webClient.post() - .uri("/oauth2.0/token") + .uri("$authHost/oauth/token") .bodyValue( request.makeBody() + mapOf( "grant_type" to grantType, @@ -75,7 +75,7 @@ data class KakaoApiClient( override fun requestOauthInfo(accessToken: String): IOAuthInfoResponse { return webClient.post() - .uri("/v2/user/me") + .uri("$apiHost/v2/user/me") .headers { headers -> headers.setBearerAuth(accessToken) } .bodyValue( mapOf(