Skip to content

Commit

Permalink
[feat #43] 구글 로그인 구현 수정 (#44)
Browse files Browse the repository at this point in the history
* feat : 누락 어노테이션 추가

* feat : 구글 로그인 구현
  • Loading branch information
dlswns2480 authored Jul 29, 2024
1 parent 1f6ccf5 commit 9a36f28
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pokit.auth.common.dto

data class GoogleUserResponse(
val email: String
)
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 9a36f28

Please sign in to comment.