Skip to content

Commit

Permalink
Merge pull request #114 from depromeet/feature/#113
Browse files Browse the repository at this point in the history
Feature/#113
  • Loading branch information
ManHyuk authored Jan 12, 2024
2 parents 2698d3b + ae39b77 commit 17777a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OAuth2UserService(
) {
OAuthProvider.GOOGLE -> {
val email =
oAuth2User.attributes["email"]?.toString() ?: throw RuntimeException("이메일이없음")
oAuth2User.attributes["email"]?.toString() ?: throw RuntimeException("구글 이메일이없음")
val name = oAuth2User.attributes["name"]?.toString()
val image = oAuth2User.attributes["picture"]?.toString() ?: ""
val user = upsert(
Expand All @@ -52,7 +52,7 @@ class OAuth2UserService(

OAuthProvider.NAVER -> {
val userInfo = oAuth2User.attributes[usernameAttributeName] as Map<String, String>
val email = userInfo["email"] ?: throw RuntimeException("이메일없음")
val email = userInfo["email"] ?: throw RuntimeException("네이버 이메일없음")
val image = userInfo["profile_image"] ?: ""
val user = upsert(
email = email,
Expand All @@ -69,12 +69,14 @@ class OAuth2UserService(
OAuthProvider.KAKAO -> {
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>

val profileImage = properties["profile_image"] ?: ""
val thumbnailImage = properties["thumbnail_image"]
val nickname = properties["nickname"]
val email = properties["email"]
val email = account["email"] ?: throw RuntimeException("카카오 이메일없음")
val user = upsert(
email = id,
email = email,
image = profileImage,
oAuthProvider = provider,
)
Expand All @@ -89,7 +91,7 @@ class OAuth2UserService(

@Transactional
fun upsert(email: String, image: String, oAuthProvider: OAuthProvider): User =
userRepository.findByEmail(email)
userRepository.findByEmailAndProvider(email, oAuthProvider)
?: createUser(email, image, oAuthProvider)

private fun createUser(email: String, image: String, oAuthProvider: OAuthProvider): User {
Expand Down
28 changes: 14 additions & 14 deletions application/api/src/main/resources/application-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ spring:
user_name_attribute: id
registration:
naver:
client-id: aa
client-secret: aa
redirect-uri: http://localhost:8080/login/oauth2/code/naver
redirect-uri: http://localhost:8080/dev/api/login/oauth2/code/naver
client-id: ${NAVER-CLIENT-ID}
client-secret: ${NAVER-CLIENT-SECRET}
authorization-grant-type: authorization_code
scope:
- email
- name
client-name: naver
kakao:
client-id: aa
redirect-uri: http://localhost:8080/api/login/oauth2/code/kakao
redirect-uri: http://localhost:8080/dev/api/login/oauth2/code/kakao
client-id: ${KAKAO-CLIENT-ID}
authorization-grant-type: authorization_code
scope:
- profile_nickname
- account_email
- profile_image
client-name: kakao
google:
redirect-uri: ${GOOGLE-REDIRECT-URI}
redirect-uri: http://localhost:8080/dev/api/login/oauth2/code/google
client-id: ${GOOGLE-CLIENT-ID}
client-secret: ${GOOGLE-CLIENT-SECRET}
scope:
Expand Down Expand Up @@ -74,20 +74,20 @@ spring:
user_name_attribute: id
registration:
naver:
client-id: aa
client-secret: aa
redirect-uri: http://localhost:8080/login/oauth2/code/naver
redirect-uri: ${NAVER-REDIRECT-URI}
client-id: ${NAVER-CLIENT-ID}
client-secret: ${NAVER-CLIENT-SECRET}
authorization-grant-type: authorization_code
scope:
- email
- name
client-name: naver
kakao:
client-id: aa
redirect-uri: http://localhost:8080/login/oauth2/code/kakao
redirect-uri: ${KAKAO-REDIRECT-URI}
client-id: ${KAKAO-CLIENT-ID}
authorization-grant-type: authorization_code
scope:
- profile_nickname
- account_email
- profile_image
client-name: kakao
google:
Expand Down Expand Up @@ -133,8 +133,8 @@ spring:
- name
client-name: naver
kakao:
client-id: ${KAKAO-CLIENT-ID}
redirect-uri: ${KAKAO-REDIRECT-URI}
client-id: ${KAKAO-CLIENT-ID}
authorization-grant-type: authorization_code
scope:
- profile_nickname
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.raemian.storage.db.core.user

import io.raemian.storage.db.core.user.enums.OAuthProvider
import org.springframework.data.jpa.repository.JpaRepository

interface UserRepository : JpaRepository<User, Long> {

fun findByEmailAndProvider(email: String, provider: OAuthProvider): User?

fun findByEmail(email: String): User?

fun existsByEmail(email: String): Boolean
Expand Down

0 comments on commit 17777a3

Please sign in to comment.