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)