Skip to content

Commit

Permalink
[#4] 애플로그인 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Oct 27, 2021
1 parent c5ace9c commit 52eb2eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
OAuth2UserService<OAuth2UserRequest, OAuth2User> delegate = new DefaultOAuth2UserService();
OAuth2User oAuth2User = delegate.loadUser(userRequest);

// OAuth2 서비스 id (구글, 카카오, 네이버)
// OAuth2 서비스 id (구글, 카카오, 네이버, 애플)
String registrationId = userRequest.getClientRegistration().getRegistrationId();
// 로그인 시, PK가 되는 필드 값 받아오기 (구글:"sub", 네이버 카카오 지원x)
String userNameAttributeName = userRequest.getClientRegistration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -50,6 +52,23 @@ private static OAuthAttributes ofGoogle(String userNameAttributeName, Map<String
.build();
}

private static OAuthAttributes ofApple(Map<String, Object> attributes) {
// JSON 형태를 Map 으로 가져오기 (kakao_account)
Map<String, Object> kakaoAccount = (Map<String, Object>) attributes.get("kakao_account");
// Profile 조회
Map<String, Object> kakaoProfile = (Map<String, Object>) 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<String, Object> attributes) {
// JSON 형태를 Map 으로 가져오기 (kakao_account)
Map<String, Object> kakaoAccount = (Map<String, Object>) attributes.get("kakao_account");
Expand Down

0 comments on commit 52eb2eb

Please sign in to comment.