-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: 카카오 로그인·회원가입 로직 및 리프레시 토큰 관리 방법 리팩토링(#70) #71
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/com/ject/studytrip/auth/application/dto/OAuthLoginOutcome.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.ject.studytrip.auth.application.dto; | ||
|
|
||
| public record OAuthLoginOutcome(Outcome outcome, TokenInfo tokenInfo, String signupKey) { | ||
| enum Outcome { | ||
| SUCCESS, | ||
| SIGNUP_REQUIRED | ||
| } | ||
|
|
||
| public static OAuthLoginOutcome success( | ||
| String accessToken, String refreshToken, long refreshTokenExpiresIn) { | ||
| return new OAuthLoginOutcome( | ||
| Outcome.SUCCESS, | ||
| new TokenInfo(accessToken, refreshToken, refreshTokenExpiresIn), | ||
| null); | ||
| } | ||
|
|
||
| public static OAuthLoginOutcome signupRequired(String signupKey) { | ||
| return new OAuthLoginOutcome(Outcome.SIGNUP_REQUIRED, null, signupKey); | ||
| } | ||
|
|
||
| public boolean isSignupRequired() { | ||
| return this.outcome == Outcome.SIGNUP_REQUIRED; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/ject/studytrip/auth/application/dto/TokenInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.ject.studytrip.auth.application.dto; | ||
|
|
||
| public record TokenInfo(String accessToken, String refreshToken, long refreshTokenExpiresIn) { | ||
| public static TokenInfo of( | ||
| String accessToken, String refreshToken, long refreshTokenExpiresIn) { | ||
| return new TokenInfo(accessToken, refreshToken, refreshTokenExpiresIn); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/ject/studytrip/auth/application/service/KakaoSignupProfileService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.ject.studytrip.auth.application.service; | ||
|
|
||
| import com.ject.studytrip.auth.domain.error.AuthErrorCode; | ||
| import com.ject.studytrip.auth.domain.model.KakaoSignupProfile; | ||
| import com.ject.studytrip.auth.domain.repository.KakaoSignupProfileRedisRepository; | ||
| import com.ject.studytrip.global.exception.CustomException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class KakaoSignupProfileService { | ||
| private final KakaoSignupProfileRedisRepository kakaoSignupProfileRedisRepository; | ||
|
|
||
| public String saveAndIssueSignupKey(String socialId, String email, String profileImageUrl) { | ||
| return kakaoSignupProfileRedisRepository.saveAndIssueSignupKey( | ||
| socialId, email, profileImageUrl); | ||
| } | ||
|
|
||
| public KakaoSignupProfile getSignupProfileByKey(String signupKey) { | ||
| if (signupKey == null || signupKey.isBlank()) { | ||
| throw new CustomException(AuthErrorCode.MISSING_KAKAO_SIGNUP_KEY); | ||
| } | ||
|
|
||
| return kakaoSignupProfileRedisRepository | ||
| .findBySignupKey(signupKey) | ||
| .orElseThrow(() -> new CustomException(AuthErrorCode.INVALID_KAKAO_SIGNUP_KEY)); | ||
| } | ||
|
|
||
| public void deleteBySignupKey(String signupKey) { | ||
| kakaoSignupProfileRedisRepository.deleteBySignupKey(signupKey); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/ject/studytrip/auth/domain/model/KakaoSignupProfile.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.ject.studytrip.auth.domain.model; | ||
|
|
||
| public record KakaoSignupProfile( | ||
| String socialId, String socialProvider, String email, String profileImageUrl) { | ||
| public static KakaoSignupProfile of( | ||
| String socialId, String socialProvider, String email, String profileImageUrl) { | ||
| return new KakaoSignupProfile(socialId, socialProvider, email, profileImageUrl); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...ain/java/com/ject/studytrip/auth/domain/repository/KakaoSignupProfileRedisRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.ject.studytrip.auth.domain.repository; | ||
|
|
||
| import com.ject.studytrip.auth.domain.model.KakaoSignupProfile; | ||
| import java.util.Optional; | ||
|
|
||
| public interface KakaoSignupProfileRedisRepository { | ||
| String saveAndIssueSignupKey(String socialId, String email, String profileImageUrl); | ||
|
|
||
| Optional<KakaoSignupProfile> findBySignupKey(String signupKey); | ||
|
|
||
| void deleteBySignupKey(String signupKey); | ||
| } |
52 changes: 52 additions & 0 deletions
52
.../ject/studytrip/auth/infra/repository/redis/KakaoSignupProfileRedisRepositoryAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.ject.studytrip.auth.infra.repository.redis; | ||
|
|
||
| import static com.ject.studytrip.global.common.constants.CacheKeyConstants.*; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.ject.studytrip.auth.domain.model.KakaoSignupProfile; | ||
| import com.ject.studytrip.auth.domain.repository.KakaoSignupProfileRedisRepository; | ||
| import com.ject.studytrip.member.domain.model.SocialProvider; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.TimeUnit; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class KakaoSignupProfileRedisRepositoryAdapter implements KakaoSignupProfileRedisRepository { | ||
| private static final long KAKAO_SIGNUP_PROFILE_TTL_MILLIS = 900000; | ||
|
|
||
| private final RedisTemplate<String, Object> redisTemplate; | ||
| private final ObjectMapper objectMapper; | ||
|
|
||
| @Override | ||
| public String saveAndIssueSignupKey(String socialId, String email, String profileImageUrl) { | ||
| String socialProvider = SocialProvider.KAKAO.name().toLowerCase(); | ||
| String key = issueKey(socialProvider); | ||
| KakaoSignupProfile signupProfile = | ||
| KakaoSignupProfile.of(socialId, socialProvider, email, profileImageUrl); | ||
|
|
||
| redisTemplate | ||
| .opsForValue() | ||
| .set(key, signupProfile, KAKAO_SIGNUP_PROFILE_TTL_MILLIS, TimeUnit.MILLISECONDS); | ||
|
|
||
| return key; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<KakaoSignupProfile> findBySignupKey(String signupKey) { | ||
| return Optional.ofNullable(redisTemplate.opsForValue().get(signupKey)) | ||
| .map(value -> objectMapper.convertValue(value, KakaoSignupProfile.class)); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteBySignupKey(String signupKey) { | ||
| redisTemplate.delete(signupKey); | ||
| } | ||
|
|
||
| private String issueKey(String socialProvider) { | ||
| return OAUTH_SIGNUP_PROFILE_PREFIX.formatted(socialProvider) + UUID.randomUUID(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
refreshTokenExpiresIn(리프레시토큰 만료시간)을 DTO에 같이 담아서 전달하고 있네요. 같이 전달한 이유가 궁금합니다.Uh oh!
There was an error while loading. Please reload this page.
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.
쿠키 관리는
HTTP와 관련된 로직이므로Presentation계층에서 전담하도록 설정해두었습니다.리프레시 토큰과 쿠키의 만료시간을 동일하게 관리하기 위해
Application계층의TokenInfoDTO에서 발급된 리프레시 토큰의 만료시간을 함께 반환하고,Presentation계층에서 리프레시 쿠키를 생성할 때 토큰의 실제 만료시간을 기준으로 쿠키의 생명주기를 정확하게 관리하고자refreshTokenExpiresIn(리프레시토큰 만료시간)을 함께 반환하도록 구성했습니다.