Skip to content

Commit

Permalink
Feat: Kakao 로그인 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
goalSetter09 committed Jul 14, 2024
1 parent 3a0147d commit 0923294
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/main/java/com/cotato/squadus/common/dto/OAuth2Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ public class OAuth2Attribute {
public static OAuth2Attribute of(String registrationId, Map<String, Object> attributes) {
if(registrationId.equals("google")){
return ofGoogle(attributes);
} else if(registrationId.equals("kakao")){
return ofKakao(attributes);
}
return ofNaver(attributes);
}

private static OAuth2Attribute ofKakao(Map<String, Object> attributes) {
Map<String, Object> kakao_account = (Map<String, Object>) attributes.get("kakao_account"); // 카카오로 받은 데이터에서 계정 정보가 담긴 kakao_account 값을 꺼낸다.
Map<String, Object> profile = (Map<String, Object>) 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<String, Object> attributes) {
return OAuth2Attribute.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0923294

Please sign in to comment.