From fe1a809058509df3eab6753d459569f5dd6f939c Mon Sep 17 00:00:00 2001 From: ktj1997 Date: Tue, 23 Jan 2024 01:07:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20oAuth=EC=97=90=20id,=20thumbnail=5Fimag?= =?UTF-8?q?e,nick=5Fname=20email=EB=B0=9B=EC=95=84=EC=98=A4=EA=B2=8C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/SecurityConfiguration.java | 6 ++-- .../core/auth/controller/AuthController.java | 15 ++++++++ .../controller/request/SignUpRequest.java | 12 +++++++ .../KakaoOAuthVendorAttributeResolver.java | 19 ---------- .../vendor/OAuthVendorAttributeResolver.java | 11 ------ .../jwt/JwtAuthenticationFilter.java | 2 +- .../jwt/JwtTokenProperties.java | 2 +- .../{ => security}/jwt/JwtTokenProvider.java | 2 +- .../{ => security}/jwt/TokenProperties.java | 2 +- .../auth/{ => security}/jwt/TokenType.java | 2 +- .../oauth2/CustomAccessDeniedHandler.java | 2 +- .../CustomAuthenticationEntryPoint.java | 2 +- .../CustomAuthenticationSuccessHandler.java | 32 ++++++++++++----- .../CustomAuthorizationRequestResolver.java | 2 +- .../oauth2/CustomClientOriginHostCache.java | 2 +- .../CustomClientRegistrationRepository.java | 2 +- .../oauth2/CustomOAuth2User.java | 4 +-- .../oauth2/CustomOAuth2UserService.java | 4 +-- .../KakaoOAuthVendorAttributeResolver.java | 36 +++++++++++++++++++ .../oauth2/vendor/OAuthVendor.java | 2 +- .../vendor/OAuthVendorAttributeResolver.java | 17 +++++++++ .../core/my/request/UpdateMyInfoRequest.java | 5 ++- .../resources/oauth/application-oauth-dev.yml | 2 ++ .../oauth/application-oauth-local.yml | 2 ++ 24 files changed, 128 insertions(+), 59 deletions(-) create mode 100644 core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/AuthController.java create mode 100644 core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/request/SignUpRequest.java delete mode 100644 core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java delete mode 100644 core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/OAuthVendorAttributeResolver.java rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/jwt/JwtAuthenticationFilter.java (97%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/jwt/JwtTokenProperties.java (90%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/jwt/JwtTokenProvider.java (98%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/jwt/TokenProperties.java (85%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/jwt/TokenType.java (54%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomAccessDeniedHandler.java (94%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomAuthenticationEntryPoint.java (94%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomAuthenticationSuccessHandler.java (70%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomAuthorizationRequestResolver.java (97%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomClientOriginHostCache.java (91%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomClientRegistrationRepository.java (96%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomOAuth2User.java (87%) rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/CustomOAuth2UserService.java (88%) create mode 100644 core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java rename core-api/src/main/java/com/imlinker/coreapi/core/auth/{ => security}/oauth2/vendor/OAuthVendor.java (86%) create mode 100644 core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/OAuthVendorAttributeResolver.java diff --git a/core-api/src/main/java/com/imlinker/coreapi/configuration/SecurityConfiguration.java b/core-api/src/main/java/com/imlinker/coreapi/configuration/SecurityConfiguration.java index ead72ae..3e3a409 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/configuration/SecurityConfiguration.java +++ b/core-api/src/main/java/com/imlinker/coreapi/configuration/SecurityConfiguration.java @@ -1,8 +1,8 @@ package com.imlinker.coreapi.configuration; -import com.imlinker.coreapi.core.auth.jwt.JwtTokenProperties; -import com.imlinker.coreapi.core.auth.jwt.TokenProperties; -import com.imlinker.coreapi.core.auth.oauth2.*; +import com.imlinker.coreapi.core.auth.security.jwt.JwtTokenProperties; +import com.imlinker.coreapi.core.auth.security.jwt.TokenProperties; +import com.imlinker.coreapi.core.auth.security.oauth2.*; import lombok.RequiredArgsConstructor; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/AuthController.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/AuthController.java new file mode 100644 index 0000000..e0cd438 --- /dev/null +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/AuthController.java @@ -0,0 +1,15 @@ +package com.imlinker.coreapi.core.auth.controller; + +import com.imlinker.coreapi.support.response.ApiResponse; +import com.imlinker.enums.OperationResult; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AuthController { + + @PostMapping + public ApiResponse signUp() { + return ApiResponse.success(OperationResult.SUCCESS); + } +} diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/request/SignUpRequest.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/request/SignUpRequest.java new file mode 100644 index 0000000..94a1834 --- /dev/null +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/controller/request/SignUpRequest.java @@ -0,0 +1,12 @@ +package com.imlinker.coreapi.core.auth.controller.request; + +import com.imlinker.domain.tag.Tag; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + +public record SignUpRequest( + @Schema(description = "oAuth 식별자") String oAuthId, + @Schema(description = "이름") String name, + @Schema(description = "프로필 이미지 URL") String profileImgUrl, + @Schema(description = "핸드폰 번호") String phoneNumber, + @Schema(description = "관심사") List tags) {} diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java deleted file mode 100644 index 3b04700..0000000 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.imlinker.coreapi.core.auth.oauth2.vendor; - -import com.imlinker.domain.common.Email; -import java.util.Map; -import org.springframework.stereotype.Component; - -@Component -public class KakaoOAuthVendorAttributeResolver implements OAuthVendorAttributeResolver { - @Override - public OAuthVendor getVendor() { - return OAuthVendor.KAKAO; - } - - @Override - public Email getEmail(Map attributes) { - Map emailAttributes = (Map) attributes.get("kakao_account"); - return Email.of(emailAttributes.get("email")); - } -} diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/OAuthVendorAttributeResolver.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/OAuthVendorAttributeResolver.java deleted file mode 100644 index 1489e4c..0000000 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/OAuthVendorAttributeResolver.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.imlinker.coreapi.core.auth.oauth2.vendor; - -import com.imlinker.domain.common.Email; -import java.util.Map; - -public interface OAuthVendorAttributeResolver { - - OAuthVendor getVendor(); - - Email getEmail(Map attributes); -} diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtAuthenticationFilter.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtAuthenticationFilter.java similarity index 97% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtAuthenticationFilter.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtAuthenticationFilter.java index 266123f..a92fa97 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtAuthenticationFilter.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.jwt; +package com.imlinker.coreapi.core.auth.security.jwt; import com.imlinker.coreapi.support.exception.FilterExceptionHandler; import com.imlinker.error.ErrorType; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtTokenProperties.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtTokenProperties.java similarity index 90% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtTokenProperties.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtTokenProperties.java index 573a30c..816a546 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtTokenProperties.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtTokenProperties.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.jwt; +package com.imlinker.coreapi.core.auth.security.jwt; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtTokenProvider.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtTokenProvider.java similarity index 98% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtTokenProvider.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtTokenProvider.java index aeb951b..8d13842 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/JwtTokenProvider.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/JwtTokenProvider.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.jwt; +package com.imlinker.coreapi.core.auth.security.jwt; import com.imlinker.coreapi.support.exception.FilterExceptionHandler; import com.imlinker.domain.common.Email; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/TokenProperties.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/TokenProperties.java similarity index 85% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/TokenProperties.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/TokenProperties.java index 21bdb09..7d38357 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/TokenProperties.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/TokenProperties.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.jwt; +package com.imlinker.coreapi.core.auth.security.jwt; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/TokenType.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/TokenType.java similarity index 54% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/TokenType.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/TokenType.java index 0f59bad..c2b0a09 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/jwt/TokenType.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/jwt/TokenType.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.jwt; +package com.imlinker.coreapi.core.auth.security.jwt; public enum TokenType { ACCESS_TOKEN, diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAccessDeniedHandler.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAccessDeniedHandler.java similarity index 94% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAccessDeniedHandler.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAccessDeniedHandler.java index 66a44eb..47945d8 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAccessDeniedHandler.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAccessDeniedHandler.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; import com.imlinker.coreapi.support.exception.FilterExceptionHandler; import com.imlinker.error.ErrorType; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthenticationEntryPoint.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthenticationEntryPoint.java similarity index 94% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthenticationEntryPoint.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthenticationEntryPoint.java index 441c3c8..d77bb6d 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthenticationEntryPoint.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; import com.imlinker.coreapi.support.exception.FilterExceptionHandler; import com.imlinker.error.ErrorType; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthenticationSuccessHandler.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthenticationSuccessHandler.java similarity index 70% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthenticationSuccessHandler.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthenticationSuccessHandler.java index 19f636c..4eac303 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthenticationSuccessHandler.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthenticationSuccessHandler.java @@ -1,9 +1,9 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; -import com.imlinker.coreapi.core.auth.jwt.JwtTokenProvider; -import com.imlinker.coreapi.core.auth.jwt.TokenType; -import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendor; -import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendorAttributeResolver; +import com.imlinker.coreapi.core.auth.security.jwt.JwtTokenProvider; +import com.imlinker.coreapi.core.auth.security.jwt.TokenType; +import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendor; +import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendorAttributeResolver; import com.imlinker.domain.common.Email; import com.imlinker.domain.user.UserService; import com.imlinker.error.ApplicationException; @@ -11,6 +11,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -64,11 +66,25 @@ public void onAuthenticationSuccess( String refreshToken = jwtTokenProvider.generateToken(email, TokenType.REFRESH_TOKEN); String redirectUri = - String.format( - "%s?accessToken=%s&refreshToken=%s", clientOriginHost, accessToken, refreshToken); + clientOriginHost + + "?" + + String.format( + "%s?accessToken=%s&refreshToken=%s", clientOriginHost, accessToken, refreshToken); getRedirectStrategy().sendRedirect(request, response, redirectUri); } else { - String redirectUri = String.format("%s?email=%s", clientOriginHost, email.getValue()); + String oAuthId = resolver.getOAuthId(oAuth2User.getAttributes()); + String nickname = resolver.getNickname(oAuth2User.getAttributes()); + String profileImgUrl = resolver.getProfileImgUrl(oAuth2User.getAttributes()); + + String redirectUri = + clientOriginHost + + "?" + + URLEncoder.encode( + String.format( + "oAuthId=%s&nickname=%s&profileImgUrl=%s&email=%s", + oAuthId, nickname, profileImgUrl, email.getValue()), + StandardCharsets.UTF_8); + getRedirectStrategy().sendRedirect(request, response, redirectUri); } } diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthorizationRequestResolver.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthorizationRequestResolver.java similarity index 97% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthorizationRequestResolver.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthorizationRequestResolver.java index fad7d03..24fb80d 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomAuthorizationRequestResolver.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomAuthorizationRequestResolver.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; import jakarta.servlet.http.HttpServletRequest; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomClientOriginHostCache.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomClientOriginHostCache.java similarity index 91% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomClientOriginHostCache.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomClientOriginHostCache.java index c764ca4..474c602 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomClientOriginHostCache.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomClientOriginHostCache.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; import com.imlinker.localcache.LocalCache; import java.time.Duration; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomClientRegistrationRepository.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomClientRegistrationRepository.java similarity index 96% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomClientRegistrationRepository.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomClientRegistrationRepository.java index a37024f..1f51800 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomClientRegistrationRepository.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomClientRegistrationRepository.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; import com.imlinker.error.ApplicationException; import com.imlinker.error.ErrorType; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomOAuth2User.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomOAuth2User.java similarity index 87% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomOAuth2User.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomOAuth2User.java index f05da76..3df9aed 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomOAuth2User.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomOAuth2User.java @@ -1,6 +1,6 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; -import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendor; +import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendor; import java.util.Collection; import java.util.Collections; import java.util.Map; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomOAuth2UserService.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomOAuth2UserService.java similarity index 88% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomOAuth2UserService.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomOAuth2UserService.java index 04aed60..5d09af7 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/CustomOAuth2UserService.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/CustomOAuth2UserService.java @@ -1,6 +1,6 @@ -package com.imlinker.coreapi.core.auth.oauth2; +package com.imlinker.coreapi.core.auth.security.oauth2; -import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendor; +import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java new file mode 100644 index 0000000..4958c1f --- /dev/null +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/KakaoOAuthVendorAttributeResolver.java @@ -0,0 +1,36 @@ +package com.imlinker.coreapi.core.auth.security.oauth2.vendor; + +import com.imlinker.domain.common.Email; +import java.util.Map; +import org.springframework.stereotype.Component; + +@Component +public class KakaoOAuthVendorAttributeResolver implements OAuthVendorAttributeResolver { + @Override + public OAuthVendor getVendor() { + return OAuthVendor.KAKAO; + } + + @Override + public String getOAuthId(Map attributes) { + return attributes.get("id").toString(); + } + + @Override + public Email getEmail(Map attributes) { + Map emailAttributes = (Map) attributes.get("kakao_account"); + return Email.of(emailAttributes.get("email")); + } + + @Override + public String getProfileImgUrl(Map attributes) { + Map emailAttributes = (Map) attributes.get("properties"); + return emailAttributes.get("thumbnail_image"); + } + + @Override + public String getNickname(Map attributes) { + Map emailAttributes = (Map) attributes.get("properties"); + return emailAttributes.get("nickname"); + } +} diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/OAuthVendor.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/OAuthVendor.java similarity index 86% rename from core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/OAuthVendor.java rename to core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/OAuthVendor.java index 02b1609..69e8262 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/auth/oauth2/vendor/OAuthVendor.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/OAuthVendor.java @@ -1,4 +1,4 @@ -package com.imlinker.coreapi.core.auth.oauth2.vendor; +package com.imlinker.coreapi.core.auth.security.oauth2.vendor; import com.imlinker.error.ApplicationException; import com.imlinker.error.ErrorType; diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/OAuthVendorAttributeResolver.java b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/OAuthVendorAttributeResolver.java new file mode 100644 index 0000000..cb33e2a --- /dev/null +++ b/core-api/src/main/java/com/imlinker/coreapi/core/auth/security/oauth2/vendor/OAuthVendorAttributeResolver.java @@ -0,0 +1,17 @@ +package com.imlinker.coreapi.core.auth.security.oauth2.vendor; + +import com.imlinker.domain.common.Email; +import java.util.Map; + +public interface OAuthVendorAttributeResolver { + + OAuthVendor getVendor(); + + String getOAuthId(Map attributes); + + Email getEmail(Map attributes); + + String getProfileImgUrl(Map attributes); + + String getNickname(Map attributes); +} diff --git a/core-api/src/main/java/com/imlinker/coreapi/core/my/request/UpdateMyInfoRequest.java b/core-api/src/main/java/com/imlinker/coreapi/core/my/request/UpdateMyInfoRequest.java index e643ad9..eae1864 100644 --- a/core-api/src/main/java/com/imlinker/coreapi/core/my/request/UpdateMyInfoRequest.java +++ b/core-api/src/main/java/com/imlinker/coreapi/core/my/request/UpdateMyInfoRequest.java @@ -1,11 +1,10 @@ package com.imlinker.coreapi.core.my.request; +import com.imlinker.domain.tag.Tag; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; public record UpdateMyInfoRequest( @Schema(description = "이름") String name, @Schema(description = "프로필 이미지 URL") String profileImgUrl, - @Schema(description = "직업", nullable = true) String job, - @Schema(description = "소속", nullable = true) String association, - @Schema(description = "관심사") List tags) {} + @Schema(description = "관심사") List tags) {} diff --git a/core-api/src/main/resources/oauth/application-oauth-dev.yml b/core-api/src/main/resources/oauth/application-oauth-dev.yml index 6ef2540..c23bed5 100644 --- a/core-api/src/main/resources/oauth/application-oauth-dev.yml +++ b/core-api/src/main/resources/oauth/application-oauth-dev.yml @@ -12,6 +12,8 @@ spring: client-name: kakao scope: - account_email + - profile_nickname + - profile_image provider: kakao: authorization-uri: https://kauth.kakao.com/oauth/authorize diff --git a/core-api/src/main/resources/oauth/application-oauth-local.yml b/core-api/src/main/resources/oauth/application-oauth-local.yml index 8ffce61..5bdcd4b 100644 --- a/core-api/src/main/resources/oauth/application-oauth-local.yml +++ b/core-api/src/main/resources/oauth/application-oauth-local.yml @@ -12,6 +12,8 @@ spring: client-name: kakao scope: - account_email + - profile_nickname + - profile_image provider: kakao: authorization-uri: https://kauth.kakao.com/oauth/authorize