File tree Expand file tree Collapse file tree 3 files changed +56
-2
lines changed
java/com/back/global/security/oauth Expand file tree Collapse file tree 3 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 2828@ Service
2929@ RequiredArgsConstructor
3030public class CustomOAuth2UserService extends DefaultOAuth2UserService {
31-
3231 private final UserRepository userRepository ;
33- private final UserProfileRepository userProfileRepository ;
3432
3533 @ Override
3634 public OAuth2User loadUser (OAuth2UserRequest userRequest ) throws OAuth2AuthenticationException {
@@ -45,6 +43,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
4543 // 소셜 제공자별로 사용자 정보 매핑
4644 OAuth2UserInfo userInfo = switch (registrationId ) {
4745 case "kakao" -> new KakaoOAuth2UserInfo (attributes );
46+ case "naver" -> new NaverOAuth2UserInfo (attributes );
4847 default -> throw new CustomException (ErrorCode .UNSUPPORTED_OAUTH_PROVIDER );
4948 };
5049
Original file line number Diff line number Diff line change 1+ package com .back .global .security .oauth ;
2+
3+ import java .util .Map ;
4+
5+ /**
6+ * 네이버 OAuth2 사용자 정보 구현체
7+ */
8+ public class NaverOAuth2UserInfo implements OAuth2UserInfo {
9+ private final Map <String , Object > attributes ;
10+
11+ public NaverOAuth2UserInfo (Map <String , Object > attributes ) {
12+ this .attributes = attributes ;
13+ }
14+
15+ @ Override
16+ public String getProvider () {
17+ return "naver" ;
18+ }
19+
20+ @ Override
21+ public String getProviderId () {
22+ Map <String , Object > response = (Map <String , Object >) attributes .get ("response" );
23+ return response != null ? (String ) response .get ("id" ) : null ;
24+ }
25+
26+ @ Override
27+ public String getEmail () {
28+ Map <String , Object > response = (Map <String , Object >) attributes .get ("response" );
29+ return response != null ? (String ) response .get ("email" ) : null ;
30+ }
31+
32+ @ Override
33+ public String getNickname () {
34+ Map <String , Object > response = (Map <String , Object >) attributes .get ("response" );
35+ return response != null ? (String ) response .get ("nickname" ) : null ;
36+ }
37+
38+ @ Override
39+ public String getProfileImageUrl () {
40+ Map <String , Object > response = (Map <String , Object >) attributes .get ("response" );
41+ return response != null ? (String ) response .get ("profile_image" ) : null ;
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -34,12 +34,24 @@ spring:
3434 redirect-uri : " {baseUrl}/login/oauth2/code/{registrationId}"
3535 scope : profile_nickname, profile_image, account_email
3636 client-name : Kakao
37+ naver :
38+ client-id : ${NAVER_CLIENT_ID}
39+ client-secret : ${NAVER_CLIENT_SECRET}
40+ authorization-grant-type : authorization_code
41+ redirect-uri : " {baseUrl}/login/oauth2/code/{registrationId}"
42+ scope : email, nickname, profile_image
43+ client-name : Naver
3744 provider :
3845 kakao :
3946 authorization-uri : https://kauth.kakao.com/oauth/authorize
4047 token-uri : https://kauth.kakao.com/oauth/token
4148 user-info-uri : https://kapi.kakao.com/v2/user/me
4249 user-name-attribute : id
50+ naver :
51+ authorization-uri : https://nid.naver.com/oauth2.0/authorize
52+ token-uri : https://nid.naver.com/oauth2.0/token
53+ user-info-uri : https://openapi.naver.com/v1/nid/me
54+ user-name-attribute : response
4355
4456springdoc :
4557 default-produces-media-type : application/json;charset=UTF-8
You can’t perform that action at this time.
0 commit comments