-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 로그인 완료 후 회원 정보 조회시 Access · RefreshToken 반환 #98
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f614c11
[fix] build.gradle jjwt 0.9.1과 0.11.x 의존성 혼용 문제 해결 및 의존성 정리
iamseojin ccd34e2
[feat] 로그인 회원 조회시 토큰 정보 함께 조회
iamseojin c93535e
[feat] 보안성 강화를 위한 HttpOnly Cookie로 RefreshToken 전달
iamseojin b77a3f9
[fix] 클라이언트와의 호환을 위한 로그인 직후 refreshToken 응답 바디로 전달
iamseojin abc845d
Setter 제거
LEEDONGH00N 0ac5139
Setter 제거
LEEDONGH00N 63540aa
Update src/main/java/com/arom/with_travel/domain/member/dto/MemberSig…
LEEDONGH00N 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
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/arom/with_travel/domain/member/dto/MemberSignupTokenResponse.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.arom.with_travel.domain.member.dto; | ||
|
|
||
| import com.arom.with_travel.global.jwt.dto.response.AuthTokenResponse; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class MemberSignupTokenResponse { | ||
| private MemberSignupResponseDto memberSignupDto; | ||
| private AuthTokenResponse tokenDto; | ||
| } |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/arom/with_travel/global/jwt/dto/response/AuthTokenResponse.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.arom.with_travel.global.jwt.dto.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class AuthTokenResponse { | ||
| private String accessToken; | ||
| private String refreshToken; | ||
| } |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,14 +2,18 @@ | |||||
|
|
||||||
| import com.arom.with_travel.domain.member.Member; | ||||||
| import com.arom.with_travel.domain.member.service.MemberService; | ||||||
| import com.arom.with_travel.domain.member.service.MemberSignupService; | ||||||
| import com.arom.with_travel.global.exception.BaseException; | ||||||
| import com.arom.with_travel.global.exception.error.ErrorCode; | ||||||
| import com.arom.with_travel.global.jwt.config.JwtProperties; | ||||||
| import com.arom.with_travel.global.jwt.domain.RefreshToken; | ||||||
| import com.arom.with_travel.global.jwt.dto.response.AuthTokenResponse; | ||||||
| import com.arom.with_travel.global.jwt.repository.RefreshTokenRepository; | ||||||
| import jakarta.servlet.http.HttpServletResponse; | ||||||
| import jakarta.transaction.Transactional; | ||||||
| import lombok.RequiredArgsConstructor; | ||||||
| import lombok.extern.slf4j.Slf4j; | ||||||
| import org.springframework.http.HttpHeaders; | ||||||
| import org.springframework.http.ResponseCookie; | ||||||
| import org.springframework.stereotype.Service; | ||||||
|
|
||||||
| import java.time.Duration; | ||||||
|
|
@@ -24,7 +28,7 @@ public class TokenService { | |||||
| private final RefreshTokenService refreshTokenService; | ||||||
| private final MemberService memberService; | ||||||
| private final RefreshTokenRepository refreshTokenRepository; | ||||||
| private final MemberSignupService memberSignupService; | ||||||
| private final JwtProperties jwtProperties; | ||||||
|
|
||||||
| // 새로운 액세스 토큰 생성 | ||||||
| public String createNewAccessToken(String refreshToken) { | ||||||
|
|
@@ -51,4 +55,30 @@ public void validateRefreshTokenOrElseThrow(String refreshToken) { | |||||
| throw BaseException.from(ErrorCode.INVALID_TOKEN); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public AuthTokenResponse issueTokenPair(String loginEmail, HttpServletResponse response) { | ||||||
|
|
||||||
| Member member = memberService.getUserByLoginEmailOrElseThrow(loginEmail); | ||||||
|
|
||||||
| String accessToken = tokenProvider.generateToken( | ||||||
| member, | ||||||
| Duration.ofHours(jwtProperties.getAccessTokenExpireHours()) | ||||||
| ); | ||||||
|
|
||||||
| String refreshToken = tokenProvider.generateToken( | ||||||
| member, | ||||||
| Duration.ofDays(jwtProperties.getRefreshTokenExpireDays()) | ||||||
| ); | ||||||
|
|
||||||
| // HttpOnly 쿠키 설정 | ||||||
| ResponseCookie cookie = ResponseCookie.from(jwtProperties.getRefreshCookieName(), refreshToken) | ||||||
| .httpOnly(true) | ||||||
| .secure(true) | ||||||
| .path("/") | ||||||
| .maxAge(Duration.ofDays(jwtProperties.getRefreshTokenExpireDays())) | ||||||
| .build(); | ||||||
| response.addHeader(HttpHeaders.SET_COOKIE, cookie.toString()); | ||||||
|
|
||||||
| return new AuthTokenResponse(accessToken, refreshToken); | ||||||
|
||||||
| return new AuthTokenResponse(accessToken, refreshToken); | |
| return new AuthTokenResponse(accessToken); |
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.
쿠키 설정 없이 문자열만 있으면 될 것 같습니다.