Skip to content

Commit

Permalink
[feat #113] 네이버 소셜로그인 로직 (#114)
Browse files Browse the repository at this point in the history
* [fix] : Provider.naver -> Provider.kakao 수정

* [feat] : Naver Oauth 응답객체 NaverResponse 추가

* [feat] : Kakao, Naver 인증 객체에 따른 Oauth 객체 생성 로직 추가
  • Loading branch information
dudxo authored Sep 20, 2024
1 parent 2689b75 commit 3855069
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public KakaoResponse(Map<String, Object> attribute) {

@Override
public String getProvider() {
return Provider.NAVER.getLabel();
return Provider.KAKAO.getLabel();
}

@Override
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/com/dnd/gongmuin/security/oauth2/NaverResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.dnd.gongmuin.security.oauth2;

import java.util.Map;

import com.dnd.gongmuin.member.domain.Provider;

public class NaverResponse implements Oauth2Response {

private final Map<String, Object> attribute;

public NaverResponse(Map<String, Object> attribute) {
this.attribute = (Map<String, Object>)attribute.get("response");
}

@Override
public String getProvider() {
return Provider.NAVER.getLabel();
}

@Override
public String getProviderId() {
return this.attribute.get("id").toString();
}

@Override
public String getEmail() {
return this.attribute.get("email").toString();
}

@Override
public String getName() {
return this.attribute.get("name").toString();
}

@Override
public String createSocialEmail() {
return String.format("%s%s/%s",
this.getProvider(),
this.getProviderId(),
this.getEmail()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.gongmuin.security.service;

import static com.dnd.gongmuin.auth.exception.AuthErrorCode.*;
import static com.dnd.gongmuin.member.domain.Provider.*;

import java.util.Objects;

Expand All @@ -17,6 +18,7 @@
import com.dnd.gongmuin.security.oauth2.AuthInfo;
import com.dnd.gongmuin.security.oauth2.CustomOauth2User;
import com.dnd.gongmuin.security.oauth2.KakaoResponse;
import com.dnd.gongmuin.security.oauth2.NaverResponse;
import com.dnd.gongmuin.security.oauth2.Oauth2Response;

import lombok.RequiredArgsConstructor;
Expand All @@ -35,8 +37,10 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
String registrationId = userRequest.getClientRegistration().getRegistrationId();
Oauth2Response oauth2Response = null;

if (Objects.equals(registrationId, "kakao")) {
if (Objects.equals(registrationId, KAKAO.getLabel())) {
oauth2Response = new KakaoResponse(oAuth2User.getAttributes());
} else if (Objects.equals(registrationId, NAVER.getLabel())) {
oauth2Response = new NaverResponse(oAuth2User.getAttributes());
} else {
throw new OAuth2AuthenticationException(
new OAuth2Error(UNSUPPORTED_SOCIAL_LOGIN.getCode()),
Expand Down

0 comments on commit 3855069

Please sign in to comment.