diff --git a/src/main/java/com/cotato/squadus/common/dto/OAuth2Attribute.java b/src/main/java/com/cotato/squadus/common/dto/OAuth2Attribute.java index 923980d..b0008a2 100644 --- a/src/main/java/com/cotato/squadus/common/dto/OAuth2Attribute.java +++ b/src/main/java/com/cotato/squadus/common/dto/OAuth2Attribute.java @@ -22,10 +22,24 @@ public class OAuth2Attribute { public static OAuth2Attribute of(String registrationId, Map attributes) { if(registrationId.equals("google")){ return ofGoogle(attributes); + } else if(registrationId.equals("kakao")){ + return ofKakao(attributes); } return ofNaver(attributes); } + private static OAuth2Attribute ofKakao(Map attributes) { + Map kakao_account = (Map) attributes.get("kakao_account"); // 카카오로 받은 데이터에서 계정 정보가 담긴 kakao_account 값을 꺼낸다. + Map profile = (Map) kakao_account.get("profile"); // 마찬가지로 profile(nickname, image_url.. 등) 정보가 담긴 값을 꺼낸다. + + return OAuth2Attribute.builder() + .name(profile.get("nickname").toString()) + .email(kakao_account.get("email").toString()) + .providerId(attributes.get("id").toString()) + .attributes(attributes) + .build(); + } + private static OAuth2Attribute ofGoogle(Map attributes) { return OAuth2Attribute.builder() diff --git a/src/main/java/com/cotato/squadus/common/oauth2/CustomOAuth2UserService.java b/src/main/java/com/cotato/squadus/common/oauth2/CustomOAuth2UserService.java index da935f1..4821c90 100644 --- a/src/main/java/com/cotato/squadus/common/oauth2/CustomOAuth2UserService.java +++ b/src/main/java/com/cotato/squadus/common/oauth2/CustomOAuth2UserService.java @@ -24,7 +24,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic OAuth2User oAuth2User = super.loadUser(userRequest); - String registrationId = userRequest.getClientRegistration().getRegistrationId(); //naver, google + String registrationId = userRequest.getClientRegistration().getRegistrationId(); //naver, google, kakao OAuth2Attribute attribute = OAuth2Attribute.of(registrationId, oAuth2User.getAttributes()); String uniqueId = registrationId+" "+attribute.getProviderId();