Skip to content

Commit 29923ae

Browse files
authored
Merge pull request #181 from checkmo2025/feat/158/NaverLogin
[Feat] 네이버 소셜 로그인 추가
2 parents 9dfbd00 + 29f0905 commit 29923ae

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/main/java/checkmo/authentication/internal/entity/Provider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public abstract class Provider {
44

55
public static final String GOOGLE = "google";
66
public static final String KAKAO = "kakao";
7+
public static final String NAVER = "naver";
78

89
public static abstract class Google {
910
public static final String EMAIL = "email";
@@ -15,4 +16,10 @@ public static abstract class Kakao {
1516
public static final String EMAIL = "email";
1617
public static final String PROVIDER_ID = "id";
1718
}
19+
20+
public static abstract class Naver {
21+
public static final String RESPONSE = "response";
22+
public static final String EMAIL = "email";
23+
public static final String PROVIDER_ID = "id";
24+
}
1825
}

src/main/java/checkmo/authentication/internal/security/oauth2/CustomOAuth2UserService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Spring Security DefaultOAuth2UserService 구현체
2020
* <p>
21-
* 소셜 로그인 시 카카오, 구글로부터 받은 사용자 정보를 처리 기존 회원 인지 신규 회원인지에 따라 다르게 처리하기 추가 정보 입력(닉네임, 관심 도서 분야 등) 필요 여부도 결정
21+
* 소셜 로그인 시 카카오, 구글, 네이버로부터 받은 사용자 정보를 처리 기존 회원 인지 신규 회원인지에 따라 다르게 처리하기 추가 정보 입력(닉네임, 관심 도서 분야 등) 필요 여부도 결정
2222
*/
2323
@Service
2424
@RequiredArgsConstructor

src/main/java/checkmo/authentication/internal/security/oauth2/OAuth2Attributes.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static OAuth2Attributes of(String registrationId, Map<String, Object> att
1818
return switch (registrationId.toLowerCase()) {
1919
case Provider.GOOGLE -> ofGoogle(attributes);
2020
case Provider.KAKAO -> ofKakao(attributes);
21+
case Provider.NAVER -> ofNaver(attributes);
2122
default -> throw new IllegalArgumentException("지원하지 않는 소셜 로그인입니다: " + registrationId);
2223
};
2324
}
@@ -36,4 +37,12 @@ private static OAuth2Attributes ofKakao(Map<String, Object> attributes) {
3637
.providerId(String.valueOf(attributes.get(Provider.Kakao.PROVIDER_ID)))
3738
.build();
3839
}
40+
41+
private static OAuth2Attributes ofNaver(Map<String, Object> attributes) {
42+
Map<String, Object> response = (Map<String, Object>) attributes.get(Provider.Naver.RESPONSE);
43+
return OAuth2Attributes.builder()
44+
.email((String) response.get(Provider.Naver.EMAIL))
45+
.providerId((String) response.get(Provider.Naver.PROVIDER_ID))
46+
.build();
47+
}
3948
}

0 commit comments

Comments
 (0)