-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
36 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
adapters/out-web/src/main/kotlin/com/pokit/auth/common/dto/GoogleUserResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
17 changes: 17 additions & 0 deletions
17
adapters/out-web/src/main/kotlin/com/pokit/auth/common/support/GoogleFeignClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
17 changes: 10 additions & 7 deletions
17
adapters/out-web/src/main/kotlin/com/pokit/auth/impl/GoogleApiAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters