diff --git a/src/main/java/side/onetime/auth/dto/GoogleUserInfo.java b/src/main/java/side/onetime/auth/dto/GoogleUserInfo.java index 4037b06..94bb596 100644 --- a/src/main/java/side/onetime/auth/dto/GoogleUserInfo.java +++ b/src/main/java/side/onetime/auth/dto/GoogleUserInfo.java @@ -24,4 +24,9 @@ public String getProvider() { public String getName() { return (String) attributes.get("name"); } + + @Override + public String getEmail() { + return (String) attributes.get("email"); + } } \ No newline at end of file diff --git a/src/main/java/side/onetime/auth/dto/KakaoUserInfo.java b/src/main/java/side/onetime/auth/dto/KakaoUserInfo.java index d288e32..d5c6b8c 100644 --- a/src/main/java/side/onetime/auth/dto/KakaoUserInfo.java +++ b/src/main/java/side/onetime/auth/dto/KakaoUserInfo.java @@ -12,7 +12,6 @@ public class KakaoUserInfo implements OAuth2UserInfo { @Override public String getProviderId() { - // Long 타입이기 때문에 toString으로 변환 return attributes.get("id").toString(); } @@ -23,7 +22,11 @@ public String getProvider() { @Override public String getName() { - // kakao_account라는 Map에서 추출 return (String) ((Map) attributes.get("properties")).get("nickname"); } + + @Override + public String getEmail() { + return (String) ((Map) attributes.get("kakao_account")).get("email"); + } } \ No newline at end of file diff --git a/src/main/java/side/onetime/auth/dto/NaverUserInfo.java b/src/main/java/side/onetime/auth/dto/NaverUserInfo.java index 3ac4398..98bb5c0 100644 --- a/src/main/java/side/onetime/auth/dto/NaverUserInfo.java +++ b/src/main/java/side/onetime/auth/dto/NaverUserInfo.java @@ -24,4 +24,9 @@ public String getProvider() { public String getName() { return (String) attributes.get("name"); } + + @Override + public String getEmail() { + return (String) attributes.get("email"); + } } \ No newline at end of file diff --git a/src/main/java/side/onetime/auth/dto/OAuth2UserInfo.java b/src/main/java/side/onetime/auth/dto/OAuth2UserInfo.java index f6e850c..8e093e5 100644 --- a/src/main/java/side/onetime/auth/dto/OAuth2UserInfo.java +++ b/src/main/java/side/onetime/auth/dto/OAuth2UserInfo.java @@ -4,4 +4,5 @@ public interface OAuth2UserInfo { String getProviderId(); String getProvider(); String getName(); + String getEmail(); } \ No newline at end of file diff --git a/src/main/java/side/onetime/auth/handler/OAuthLoginSuccessHandler.java b/src/main/java/side/onetime/auth/handler/OAuthLoginSuccessHandler.java index 698d57b..2602c80 100644 --- a/src/main/java/side/onetime/auth/handler/OAuthLoginSuccessHandler.java +++ b/src/main/java/side/onetime/auth/handler/OAuthLoginSuccessHandler.java @@ -75,6 +75,7 @@ private OAuth2UserInfo extractOAuth2UserInfo(OAuth2AuthenticationToken token, St private void handleAuthentication(HttpServletRequest request, HttpServletResponse response, OAuth2UserInfo oAuth2UserInfo, String provider) throws IOException { String providerId = oAuth2UserInfo.getProviderId(); String name = oAuth2UserInfo.getName(); + String email = oAuth2UserInfo.getEmail(); User existUser = userRepository.findByProviderId(providerId); @@ -86,9 +87,10 @@ private void handleAuthentication(HttpServletRequest request, HttpServletRespons handleExistingUser(request, response, existUser); } - log.info("유저 이름 : {}", name); + log.info("NAME : {}", name); log.info("PROVIDER : {}", provider); log.info("PROVIDER_ID : {}", providerId); + log.info("EMAIL : {}", email); } // 신규 유저 처리 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yaml similarity index 98% rename from src/main/resources/application.yml rename to src/main/resources/application.yaml index 9a5d0bc..d3d5780 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yaml @@ -42,6 +42,7 @@ spring: client-secret: ${OAUTH_KAKAO_CLIENT_SECRET} scope: - profile_nickname + - account_email authorization-grant-type: authorization_code redirect-uri: ${OAUTH_KAKAO_REDIRECT_URI} client-name: Kakao