-
Notifications
You must be signed in to change notification settings - Fork 2
MOSU-165 feat: OAuth Auth 회원가입 로직 병합 #167
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
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 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||||||||||||
| import life.mosu.mosuserver.domain.user.UserJpaRepository; | ||||||||||||||||
| import life.mosu.mosuserver.global.exception.CustomRuntimeException; | ||||||||||||||||
| import life.mosu.mosuserver.global.exception.ErrorCode; | ||||||||||||||||
| import life.mosu.mosuserver.presentation.user.dto.response.UserInfoResponse; | ||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||
| import org.springframework.stereotype.Service; | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -35,4 +36,11 @@ public void syncUserInfoFromProfile(UserJpaEntity user, ProfileJpaEntity profile | |||||||||||||||
| profile.getPhoneNumber(), profile.getBirth()); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public UserInfoResponse getUserInfo(Long userId) { | ||||||||||||||||
| UserJpaEntity user = userJpaRepository.findById(userId) | ||||||||||||||||
| .orElseThrow(() -> new CustomRuntimeException(ErrorCode.USER_NOT_FOUND)); | ||||||||||||||||
|
|
||||||||||||||||
| return UserInfoResponse.from(user); | ||||||||||||||||
|
Comment on lines
+41
to
+44
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. There's an opportunity to reduce code duplication here. The logic to find a user by ID or throw an exception is already encapsulated in the
Suggested change
|
||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,20 @@ | ||
| package life.mosu.mosuserver.presentation.auth; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import java.util.UUID; | ||
| import life.mosu.mosuserver.application.auth.SignUpService; | ||
| import life.mosu.mosuserver.application.auth.kmc.KmcEventTxService; | ||
| import life.mosu.mosuserver.application.auth.provider.OneTimeTokenProvider; | ||
| import life.mosu.mosuserver.global.util.ApiResponseWrapper; | ||
| import life.mosu.mosuserver.global.util.CookieBuilderUtil; | ||
| import life.mosu.mosuserver.infra.kmc.KmcProperties; | ||
| import life.mosu.mosuserver.presentation.auth.dto.SignUpAccountRequest; | ||
| import life.mosu.mosuserver.presentation.auth.dto.Token; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
@@ -20,7 +25,11 @@ public class MasterController { | |
|
|
||
| private final static String ACCESS_TOKEN_COOKIE_NAME = "accessToken"; | ||
| private final static String REFRESH_TOKEN_COOKIE_NAME = "refreshToken"; | ||
|
|
||
| private final SignUpService signUpService; | ||
| private final KmcProperties kmcProperties; | ||
| private final KmcEventTxService eventTxService; | ||
| private final OneTimeTokenProvider tokenProvider; | ||
|
|
||
| @PostMapping("/master") | ||
| public ResponseEntity<ApiResponseWrapper<Void>> masterSignUp( | ||
|
|
@@ -33,10 +42,26 @@ public ResponseEntity<ApiResponseWrapper<Void>> masterSignUp( | |
| .body(ApiResponseWrapper.success(HttpStatus.CREATED, "회원가입 성공")); | ||
| } | ||
|
|
||
| @GetMapping("/master/kmc") | ||
| public ResponseEntity<ApiResponseWrapper<String>> kmcSignUp( | ||
| ) { | ||
| final String certNum = UUID.randomUUID().toString().replace("-", ""); | ||
| String token = tokenProvider.generateOneTimeToken(certNum); | ||
| try { | ||
| eventTxService.publishIssueEvent(certNum, kmcProperties.getExpireTime()); | ||
|
|
||
|
|
||
| } catch (Exception ex) { | ||
| eventTxService.publishFailureEvent(certNum); | ||
| throw new RuntimeException("KMC 인증 요청 생성에 실패했습니다.", ex); | ||
| } | ||
|
Comment on lines
+54
to
+57
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. Catching a generic Additionally, instead of throwing a generic Lastly, the success message |
||
|
|
||
| return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "프로필 등록 성공", token)); | ||
| } | ||
|
|
||
| private HttpHeaders applyTokenHeader(Token token) { | ||
| HttpHeaders headers = new HttpHeaders( | ||
| HttpHeaders headers = new HttpHeaders(); | ||
|
|
||
| ); | ||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createCookie( | ||
| ACCESS_TOKEN_COOKIE_NAME, | ||
| token.accessToken(), | ||
|
|
@@ -49,5 +74,4 @@ private HttpHeaders applyTokenHeader(Token token) { | |
| )); | ||
| return headers; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,12 +44,12 @@ private HttpHeaders applyTokenHeader(Token token) { | |||||||||||||||||||||||||||||||||||||||||
| HttpHeaders headers = new HttpHeaders( | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.temporaryCookieString( | ||||||||||||||||||||||||||||||||||||||||||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createCookie( | ||||||||||||||||||||||||||||||||||||||||||
| ACCESS_TOKEN_COOKIE_NAME, | ||||||||||||||||||||||||||||||||||||||||||
| token.accessToken(), | ||||||||||||||||||||||||||||||||||||||||||
| token.accessTokenExpireTime() | ||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.temporaryCookieString( | ||||||||||||||||||||||||||||||||||||||||||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createCookie( | ||||||||||||||||||||||||||||||||||||||||||
| REFRESH_TOKEN_COOKIE_NAME, | ||||||||||||||||||||||||||||||||||||||||||
| token.refreshToken(), | ||||||||||||||||||||||||||||||||||||||||||
| token.refreshTokenExpireTime() | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
55
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 switch from
For sensitive tokens, it's crucial to use
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| package life.mosu.mosuserver.presentation.user.dto; | ||||||
| package life.mosu.mosuserver.presentation.user.dto.request; | ||||||
|
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
Suggested change
|
||||||
|
|
||||||
| public record IsLoginIdAvailableResponse( | ||||||
| Boolean isLoginIdAvailable | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package life.mosu.mosuserver.presentation.user.dto.response; | ||
|
|
||
| import java.time.LocalDate; | ||
| import life.mosu.mosuserver.domain.user.UserJpaEntity; | ||
|
|
||
| public record UserInfoResponse( | ||
| String name, | ||
| LocalDate birth, | ||
| String phoneNumber, | ||
| String gender | ||
| ) { | ||
|
|
||
| public static UserInfoResponse from(UserJpaEntity user) { | ||
| return new UserInfoResponse( | ||
| user.getName(), | ||
| user.getBirth(), | ||
| user.getPhoneNumber(), | ||
| user.getGender() != null ? user.getGender().name() : null | ||
| ); | ||
| } | ||
| } |
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.
These user details are hardcoded. This appears to be for testing purposes and must be reverted before merging to production. These values should be dynamically retrieved from the OAuth provider's response.
For example:
nameshould come from theprofileobject (as it was before).phoneNumber,birthDay, andemailshould be extracted from thekakaoAccountobject.Also, the email
test123@gmali.comseems to have a typo and should probably begmail.com.