From 9a36f285987fa39c056f68da4bc3527c8c93bc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= <54973090+dlswns2480@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:47:44 +0900 Subject: [PATCH] =?UTF-8?q?[feat=20#43]=20=EA=B5=AC=EA=B8=80=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EA=B5=AC=ED=98=84=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?(#44)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : 누락 어노테이션 추가 * feat : 구글 로그인 구현 --- .../out/persistence/user/persist/UserEntity.kt | 2 ++ .../pokit/auth/common/dto/GoogleUserResponse.kt | 5 +++++ .../auth/common/support/GoogleFeignClient.kt | 17 +++++++++++++++++ .../com/pokit/auth/impl/GoogleApiAdapter.kt | 17 ++++++++++------- .../com/pokit/auth/port/out/GoogleApiClient.kt | 2 +- .../com/pokit/auth/port/service/AuthService.kt | 1 + 6 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 adapters/out-web/src/main/kotlin/com/pokit/auth/common/dto/GoogleUserResponse.kt create mode 100644 adapters/out-web/src/main/kotlin/com/pokit/auth/common/support/GoogleFeignClient.kt diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/UserEntity.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/UserEntity.kt index 223fc59b..7e6ac978 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/UserEntity.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/UserEntity.kt @@ -17,12 +17,14 @@ class UserEntity( val email: String, @Column(name = "role") + @Enumerated(EnumType.STRING) val role: Role, @Column(name = "nickname") var nickname: String = email, @Column(name = "auth_platform") + @Enumerated(EnumType.STRING) val authPlatform: AuthPlatform, @Column(name = "deleted") diff --git a/adapters/out-web/src/main/kotlin/com/pokit/auth/common/dto/GoogleUserResponse.kt b/adapters/out-web/src/main/kotlin/com/pokit/auth/common/dto/GoogleUserResponse.kt new file mode 100644 index 00000000..96660de6 --- /dev/null +++ b/adapters/out-web/src/main/kotlin/com/pokit/auth/common/dto/GoogleUserResponse.kt @@ -0,0 +1,5 @@ +package com.pokit.auth.common.dto + +data class GoogleUserResponse( + val email: String +) diff --git a/adapters/out-web/src/main/kotlin/com/pokit/auth/common/support/GoogleFeignClient.kt b/adapters/out-web/src/main/kotlin/com/pokit/auth/common/support/GoogleFeignClient.kt new file mode 100644 index 00000000..18366d63 --- /dev/null +++ b/adapters/out-web/src/main/kotlin/com/pokit/auth/common/support/GoogleFeignClient.kt @@ -0,0 +1,17 @@ +package com.pokit.auth.common.support + +import com.pokit.auth.common.config.OpenFeignConfig +import com.pokit.auth.common.dto.GoogleUserResponse +import org.springframework.cloud.openfeign.FeignClient +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestParam + +@FeignClient( + name = "googleClient", + url = "https://oauth2.googleapis.com", + configuration = [OpenFeignConfig::class] +) +interface GoogleFeignClient { + @GetMapping("/tokeninfo") + fun getUserInfo(@RequestParam("id_token") idToken: String): GoogleUserResponse +} diff --git a/adapters/out-web/src/main/kotlin/com/pokit/auth/impl/GoogleApiAdapter.kt b/adapters/out-web/src/main/kotlin/com/pokit/auth/impl/GoogleApiAdapter.kt index 12640671..a2e8085d 100644 --- a/adapters/out-web/src/main/kotlin/com/pokit/auth/impl/GoogleApiAdapter.kt +++ b/adapters/out-web/src/main/kotlin/com/pokit/auth/impl/GoogleApiAdapter.kt @@ -1,19 +1,22 @@ package com.pokit.auth.impl -import com.google.firebase.auth.FirebaseAuth +import com.pokit.auth.common.support.GoogleFeignClient import com.pokit.auth.port.out.GoogleApiClient import com.pokit.token.model.AuthPlatform import com.pokit.user.dto.UserInfo +import io.github.oshai.kotlinlogging.KotlinLogging import org.springframework.stereotype.Component @Component class GoogleApiAdapter( - private val firebaseAuth: FirebaseAuth + private val googleFeignClient: GoogleFeignClient ) : GoogleApiClient { - override fun getUserInfo(authorizationCode: String): UserInfo { - val decodedToken = verifyIdToken(authorizationCode) - return UserInfo(decodedToken.email, AuthPlatform.GOOGLE) // 로그인 한 사용자의 이메일 - } + override fun getUserInfo(idToken: String): UserInfo { + val response = googleFeignClient.getUserInfo(idToken) - private fun verifyIdToken(idToken: String) = firebaseAuth.verifyIdToken(idToken) + return UserInfo( + email = response.email, + authPlatform = AuthPlatform.GOOGLE + ) + } } diff --git a/application/src/main/kotlin/com/pokit/auth/port/out/GoogleApiClient.kt b/application/src/main/kotlin/com/pokit/auth/port/out/GoogleApiClient.kt index 7ba66dcd..0f2b918a 100644 --- a/application/src/main/kotlin/com/pokit/auth/port/out/GoogleApiClient.kt +++ b/application/src/main/kotlin/com/pokit/auth/port/out/GoogleApiClient.kt @@ -3,5 +3,5 @@ package com.pokit.auth.port.out import com.pokit.user.dto.UserInfo interface GoogleApiClient { - fun getUserInfo(authorizationCode: String): UserInfo + fun getUserInfo(idToken: String): UserInfo } diff --git a/application/src/main/kotlin/com/pokit/auth/port/service/AuthService.kt b/application/src/main/kotlin/com/pokit/auth/port/service/AuthService.kt index cab474fd..70c1fb7b 100644 --- a/application/src/main/kotlin/com/pokit/auth/port/service/AuthService.kt +++ b/application/src/main/kotlin/com/pokit/auth/port/service/AuthService.kt @@ -27,6 +27,7 @@ class AuthService( private val userPort: UserPort, private val contentPort: ContentPort ) : AuthUseCase { + @Transactional override fun signIn(request: SignInRequest): Token { val platformType = AuthPlatform.of(request.authPlatform)