From 52eb2eba57f147a8f5ba0870c5684227b7ba8d1e Mon Sep 17 00:00:00 2001 From: YoungJun Park Date: Thu, 28 Oct 2021 00:04:03 +0900 Subject: [PATCH] =?UTF-8?q?[#4]=20=EC=95=A0=ED=94=8C=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/auth/CustomOAuth2UserService.java | 2 +- .../api/config/auth/dto/OAuthAttributes.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/teamnexters/lazy/api/config/auth/CustomOAuth2UserService.java b/api/src/main/java/com/teamnexters/lazy/api/config/auth/CustomOAuth2UserService.java index 70f8075..d175afe 100644 --- a/api/src/main/java/com/teamnexters/lazy/api/config/auth/CustomOAuth2UserService.java +++ b/api/src/main/java/com/teamnexters/lazy/api/config/auth/CustomOAuth2UserService.java @@ -42,7 +42,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic OAuth2UserService delegate = new DefaultOAuth2UserService(); OAuth2User oAuth2User = delegate.loadUser(userRequest); - // OAuth2 서비스 id (구글, 카카오, 네이버) + // OAuth2 서비스 id (구글, 카카오, 네이버, 애플) String registrationId = userRequest.getClientRegistration().getRegistrationId(); // 로그인 시, PK가 되는 필드 값 받아오기 (구글:"sub", 네이버 카카오 지원x) String userNameAttributeName = userRequest.getClientRegistration() diff --git a/api/src/main/java/com/teamnexters/lazy/api/config/auth/dto/OAuthAttributes.java b/api/src/main/java/com/teamnexters/lazy/api/config/auth/dto/OAuthAttributes.java index a93d021..a671745 100644 --- a/api/src/main/java/com/teamnexters/lazy/api/config/auth/dto/OAuthAttributes.java +++ b/api/src/main/java/com/teamnexters/lazy/api/config/auth/dto/OAuthAttributes.java @@ -33,6 +33,8 @@ public static OAuthAttributes of(String provider, String userNameAttributeName, return ofKakao(attributes); case "naver": return ofNaver(attributes); + case "apple": + return ofApple(attributes); default: throw new OAuth2ProviderNotMatchException(provider); } @@ -50,6 +52,23 @@ private static OAuthAttributes ofGoogle(String userNameAttributeName, Map attributes) { + // JSON 형태를 Map 으로 가져오기 (kakao_account) + Map kakaoAccount = (Map) attributes.get("kakao_account"); + // Profile 조회 + Map kakaoProfile = (Map) kakaoAccount.get("profile"); + + return OAuthAttributes.builder() + .oauthId(String.valueOf(attributes.get("id"))) + .name((String) kakaoProfile.get("nickname")) + .email((String) kakaoAccount.get("email")) + .picture((String) kakaoProfile.get("profile_image_url")) + .attributes(kakaoAccount) + .nameAttributeKey("email") + .provider(Provider.KAKAO) + .build(); + } + private static OAuthAttributes ofKakao(Map attributes) { // JSON 형태를 Map 으로 가져오기 (kakao_account) Map kakaoAccount = (Map) attributes.get("kakao_account");