Skip to content

Commit

Permalink
GetOAuthInfoQueryProcessor에 KakaoApiClient 의존성을 주입한다
Browse files Browse the repository at this point in the history
  • Loading branch information
anjeongkyun committed Nov 14, 2023
1 parent ba85c15 commit 7ecf871
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 14 additions & 2 deletions api/src/main/kotlin/org/tagwonder/configs/UseCaseContext.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions gateway/src/main/kotlin/org/tagwonder/KakaoApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -46,7 +47,6 @@ data class KakaoApiClient(
private fun makeBaseUrl(): String {
return UriComponentsBuilder.newInstance()
.scheme(protocol)
.host(host)
.build()
.toUriString()
}
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 7ecf871

Please sign in to comment.