Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
egg528 committed Feb 29, 2024
1 parent 1aee726 commit 1aa3116
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.springframework.security.oauth2.core.user.OAuth2User
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional


@Service
class OAuth2UserService(
private val userRepository: UserRepository,
Expand All @@ -26,7 +27,6 @@ class OAuth2UserService(
}

override fun loadUser(userRequest: OAuth2UserRequest): OAuth2User {
val oAuth2User = super.loadUser(userRequest)
val usernameAttributeName = userRequest.clientRegistration
.providerDetails.userInfoEndpoint
.userNameAttributeName
Expand All @@ -36,11 +36,15 @@ class OAuth2UserService(
OAuthProvider.valueOf(userRequest.clientRegistration.registrationId.uppercase())
) {
OAuthProvider.APPLE -> {
val email =
oAuth2User.attributes["email"]?.toString() ?: throw RuntimeException("구글 이메일이없음")
val attributes: Map<String, Any>
val idToken = userRequest.additionalParameters["id_token"].toString()

val name = oAuth2User.attributes["name"]?.toString()
val image = oAuth2User.attributes["picture"]?.toString() ?: ""
println(idToken)
println(userRequest)

val email = "test"
val name = "test"
val image = "test"
val user = upsert(
email = email,
image = image,
Expand All @@ -53,6 +57,7 @@ class OAuth2UserService(
)
}
OAuthProvider.GOOGLE -> {
val oAuth2User = super.loadUser(userRequest)
val email =
oAuth2User.attributes["email"]?.toString() ?: throw RuntimeException("구글 이메일이없음")

Expand All @@ -71,6 +76,7 @@ class OAuth2UserService(
}

OAuthProvider.NAVER -> {
val oAuth2User = super.loadUser(userRequest)
val userInfo = oAuth2User.attributes[usernameAttributeName] as Map<String, String>
val email = userInfo["email"] ?: throw RuntimeException("네이버 이메일없음")
val image = userInfo["profile_image"] ?: ""
Expand All @@ -87,6 +93,7 @@ class OAuth2UserService(
}

OAuthProvider.KAKAO -> {
val oAuth2User = super.loadUser(userRequest)
val id = oAuth2User.attributes["id"]?.toString() ?: ""
val properties = oAuth2User.attributes["properties"] as Map<String, String>
val account = oAuth2User.attributes["kakao_account"] as Map<String, String>
Expand Down

0 comments on commit 1aa3116

Please sign in to comment.