-
Notifications
You must be signed in to change notification settings - Fork 2
[⚡배포] v1 Prod Server 배포 #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9521962
946b4a2
6c056fb
53f4a37
8d158a4
48ac0c6
e66d385
b18b225
740d1b2
c7cf389
495fbff
331f909
f39e3de
776f492
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| package life.mosu.mosuserver.application.oauth; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import life.mosu.mosuserver.domain.profile.entity.Gender; | ||
| import life.mosu.mosuserver.domain.profile.repository.ProfileJpaRepository; | ||
|
|
@@ -10,11 +12,13 @@ | |
| import life.mosu.mosuserver.domain.user.repository.UserJpaRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.core.ParameterizedTypeReference; | ||
| import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; | ||
| import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; | ||
| import org.springframework.security.oauth2.core.OAuth2AuthenticationException; | ||
| import org.springframework.security.oauth2.core.user.OAuth2User; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.reactive.function.client.WebClient; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
|
|
@@ -23,14 +27,28 @@ public class OAuthUserService extends DefaultOAuth2UserService { | |
|
|
||
| private final UserJpaRepository userRepository; | ||
| private final ProfileJpaRepository profileRepository; | ||
| private final WebClient webClient; | ||
|
|
||
| @Override | ||
| public OAuth2User loadUser(final OAuth2UserRequest userRequest) | ||
| throws OAuth2AuthenticationException { | ||
| final OAuth2User user = super.loadUser(userRequest); | ||
|
|
||
| final Map<String, Object> oAuth2UserAttributes = user.getAttributes(); | ||
| log.info("KKK OAuth2User attributes: {}", oAuth2UserAttributes); | ||
|
|
||
| Map<String, Object> serviceTermsAttributes = getServiceTerms( | ||
| userRequest.getAccessToken().getTokenValue()); | ||
|
|
||
| boolean agreedToMarketing = false; | ||
| if (serviceTermsAttributes.get("service_terms") instanceof List<?> termsList) { | ||
| agreedToMarketing = termsList.stream() | ||
| .filter(term -> term instanceof Map) | ||
| .map(term -> (Map<String, Object>) term) | ||
| .filter(termMap -> "terms_03".equals(termMap.get("tag"))) | ||
| .findFirst() | ||
| .map(termMap -> (Boolean) termMap.get("agreed")) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| final String registrationId = userRequest.getClientRegistration().getRegistrationId(); | ||
| final String userNameAttributeName = userRequest.getClientRegistration() | ||
|
|
@@ -39,7 +57,7 @@ public OAuth2User loadUser(final OAuth2UserRequest userRequest) | |
| .getUserNameAttributeName(); | ||
|
|
||
| final OAuthUserInfo userInfo = OAuthUserInfo.of(OAuthProvider.from(registrationId), | ||
| oAuth2UserAttributes); | ||
| oAuth2UserAttributes, agreedToMarketing); | ||
|
|
||
| final UserJpaEntity oAuthUser = updateOrWrite(userInfo); | ||
|
|
||
|
|
@@ -61,9 +79,8 @@ private UserJpaEntity updateOrWrite(final OAuthUserInfo info) { | |
| }) | ||
| .orElseGet(() -> { | ||
| final UserJpaEntity newUser = UserJpaEntity.builder() | ||
| //TODO kakao 정보 null일 경우 후처리 필요, ServiceTerm 승인 시 처리 구현 | ||
| .loginId(info.email() != null ? info.email() : "NA") | ||
| .gender(info.gender() != null ? info.gender() : Gender.MALE) | ||
| .gender(info.gender() != null ? info.gender() : Gender.PENDING) | ||
| .name(info.name() != null ? info.name() : "NA") | ||
| .birth(info.birthDay() != null ? info.birthDay() | ||
| : LocalDate.EPOCH) | ||
|
|
@@ -73,9 +90,30 @@ private UserJpaEntity updateOrWrite(final OAuthUserInfo info) { | |
| .provider(AuthProvider.KAKAO) | ||
| .agreedToTermsOfService(true) | ||
| .agreedToPrivacyPolicy(true) | ||
| .agreedToMarketing(false) | ||
| .agreedToMarketing(info.marketingAgreed()) | ||
| .build(); | ||
| return userRepository.save(newUser); | ||
| }); | ||
| } | ||
|
|
||
| private Map<String, Object> getServiceTerms(String accessToken) { | ||
|
|
||
| String url = "https://kapi.kakao.com/v2/user/service_terms"; | ||
|
|
||
| try { | ||
| Map<String, Object> response = webClient.get() | ||
| .uri(url) | ||
| .header("Authorization", "Bearer " + accessToken) | ||
| .retrieve() | ||
| .bodyToMono(new ParameterizedTypeReference<Map<String, Object>>() { | ||
| }) | ||
| .block(); | ||
|
|
||
| log.info(response.toString()); | ||
| return response != null ? response : Collections.emptyMap(); | ||
| } catch (Exception e) { | ||
| log.error("Failed to fetch service terms from Kakao with WebClient", e); | ||
| return Collections.emptyMap(); | ||
| } | ||
| } | ||
|
Comment on lines
+99
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method has a couple of areas for improvement:
|
||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,14 @@ | ||
| package life.mosu.mosuserver.global.config; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import life.mosu.mosuserver.global.resolver.PhoneNumberArgumentResolver; | ||
| import life.mosu.mosuserver.global.resolver.UserIdArgumentResolver; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
| import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
|
||
| import life.mosu.mosuserver.global.resolver.UserIdArgumentResolver; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Configuration | ||
| @RequiredArgsConstructor | ||
| public class WebMvcConfig implements WebMvcConfigurer { | ||
|
|
@@ -22,7 +20,6 @@ public class WebMvcConfig implements WebMvcConfigurer { | |
| public void addArgumentResolvers(final List<HandlerMethodArgumentResolver> resolvers) { | ||
| resolvers.add(userIdResolver); | ||
| resolvers.add(phoneNumberResolver); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -32,17 +29,10 @@ public void addCorsMappings(CorsRegistry registry) { | |
| .allowedHeaders("*") | ||
| .allowedOrigins( | ||
| "http://localhost:3000", | ||
| "http://localhost:8080", | ||
| "http://api.mosuedu.com", | ||
| "https://mosuedu.com", | ||
| "https://api.mosuedu.com", | ||
| "https://www.mosuedu.com", | ||
| "http://www.mosuedu.com:3000", | ||
| "https://test.mosuedu.com", | ||
| "http://localhost:5173", | ||
| "https://partnership.mosuedu.com", | ||
| "http://dev.mosuedu.com:3000", | ||
| "https://dev.mosuedu.com", | ||
| "http://admin.mosuedu.com:3000", | ||
| "https://admin.mosuedu.com" | ||
| ) | ||
|
Comment on lines
30
to
37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The list of allowed origins is duplicated here and in You can convert the list to an array as required by the .allowedOrigins(SecurityConfig.clients.toArray(new String[0])) |
||
| .allowCredentials(true) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to parse the marketing agreement status relies on
instanceofchecks and casting fromMap<String, Object>. This approach is not type-safe and can be brittle if the API response structure changes.To improve robustness and readability, I recommend creating dedicated DTOs for the Kakao service terms API response. This would allow you to leverage your JSON mapper (e.g., Jackson) for safe deserialization and eliminate manual casting.
For example, you could define classes like this:
Using these DTOs in your
WebClientcall would make this parsing logic much cleaner and safer.