-
Notifications
You must be signed in to change notification settings - Fork 1
[Feature] OAuth 로그인시 토큰 전달 방식 변경 #286
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
21 commits
Select commit
Hold shift + click to select a range
53d9a27
feat: TokenGenerateMachine 삭제
m-a-king 84cd789
feat(auth): userId로 role, accessToken 조회 기능 추가
m-a-king 012215a
feat(auth): 현재 액세스 토큰 기준 userInfo, accessToken 조회 엔드포인트 추가 및 개선
m-a-king 54618b4
feat(token): login 토큰 추가, 구조 개선
m-a-king 9f477f8
feat(user): 유저 정보 dto 정적 팩토리 메서드 추가
m-a-king f57183b
feat(user): 유저 권한 조회 기능 추가
m-a-king 4f87673
feat(refreshToken): 유저 아이디 기준 리프레시 토큰 조회 기능 추가
m-a-king ac7222f
feat(refreshToken): 유저 아이디 기준 리프레시 토큰 조회 기능 추가
m-a-king dc4d972
feat(cookie): 로그인 토큰 설정 기능 추가 및 로직 개선
m-a-king 184d620
feat(cookie): 토큰 타입 파라미터 추가 및 로직 개선
m-a-king 71bb3f9
feat(oauth): 리디렉션 주소 변경 및 로그인 토큰 발급 추가
m-a-king 580fe39
feat(token): 로그인 토큰 생성 기능 추가 및 로직 개선
m-a-king b33084b
refactor(token): 메서드 네이밍 변경
m-a-king 3aae6c9
refactor(token): 메서드 네이밍 변경
m-a-king d89bed9
refactor: 병합 충돌 해결
m-a-king 708c5ff
test: 인자 사용
m-a-king 039917b
test(jwt): 사용하지 않는 메서드 삭제
m-a-king d02e1b7
feat(auth): 메시지 수정
m-a-king 491846b
test(user): 유저 아이디 기준 유저 권한 조회 테스트 추가
m-a-king fc6c044
refactor(token): 토큰 타입 명명 수정
m-a-king 6cfe14c
refactor: 코드 리뷰 반영
m-a-king 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
Empty file.
45 changes: 45 additions & 0 deletions
45
src/main/java/com/somemore/global/auth/controller/AuthController.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,45 @@ | ||
| package com.somemore.global.auth.controller; | ||
|
|
||
| import com.somemore.global.auth.annotation.CurrentUser; | ||
| import com.somemore.global.auth.dto.UserInfoResponseDto; | ||
| import com.somemore.global.auth.jwt.domain.EncodedToken; | ||
| import com.somemore.global.auth.usecase.AuthQueryUseCase; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import com.somemore.user.domain.UserRole; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/auth") | ||
| public class AuthController { | ||
|
|
||
| private final AuthQueryUseCase authQueryUseCase; | ||
|
|
||
| @GetMapping("/user-info") | ||
| public ApiResponse<UserInfoResponseDto> getUserInfo( | ||
| @CurrentUser UUID userId | ||
| ) { | ||
| UserRole role = authQueryUseCase.getRoleByUserId(userId); | ||
|
|
||
| return ApiResponse.ok(HttpStatus.OK.value(), | ||
| UserInfoResponseDto.of(userId, role), | ||
| "유저 정보 응답 성공"); | ||
| } | ||
|
|
||
| @GetMapping("/token") | ||
| public ApiResponse<String> getToken( | ||
| @CurrentUser UUID userId | ||
| ) { | ||
| EncodedToken accessToken = authQueryUseCase.getAccessTokenByUserId(userId); | ||
|
|
||
| return ApiResponse.ok(HttpStatus.OK.value(), | ||
| accessToken.getValueWithPrefix(), | ||
| "액세스 토큰 응답 성공"); | ||
| } | ||
| } |
34 changes: 0 additions & 34 deletions
34
src/main/java/com/somemore/global/auth/controller/UserInfoQueryController.java
This file was deleted.
Oops, something went wrong.
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
4 changes: 3 additions & 1 deletion
4
src/main/java/com/somemore/global/auth/cookie/CookieUseCase.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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| package com.somemore.global.auth.cookie; | ||
|
|
||
| import com.somemore.global.auth.jwt.domain.TokenType; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
|
|
||
| public interface CookieUseCase { | ||
| void setAccessToken(HttpServletResponse response, String value); | ||
|
|
||
| void setToken(HttpServletResponse response, String value, TokenType tokenType); | ||
|
|
||
| void deleteAccessToken(HttpServletResponse response); | ||
| } |
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
25 changes: 16 additions & 9 deletions
25
src/main/java/com/somemore/global/auth/jwt/domain/TokenType.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 |
|---|---|---|
| @@ -1,20 +1,27 @@ | ||
| package com.somemore.global.auth.jwt.domain; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| import java.time.Duration; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public enum TokenType { | ||
| ACCESS(1000 * 60 * 30), | ||
| REFRESH(1000 * 60 * 60 * 24 * 7), | ||
| SIGNOUT(0); | ||
| ACCESS(Duration.ofMinutes(30)), | ||
|
Collaborator
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. Duration 기억하겠습니다... 좋네요
Collaborator
Author
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. 네 코드가 엄청 깔끔해져서 좋더라구요 |
||
| REFRESH(Duration.ofDays(7)), | ||
| SIGN_IN(Duration.ofMinutes(1)), | ||
| SIGN_OUT(Duration.ZERO); | ||
|
|
||
| private final Duration period; | ||
|
|
||
| private final int period; | ||
| public String getDescription() { | ||
| return this.name() + "_TOKEN"; | ||
| } | ||
|
|
||
| TokenType(int period) { | ||
| this.period = period; | ||
| public int getPeriodInMillis() { | ||
| return Math.toIntExact(period.toMillis()); | ||
| } | ||
|
|
||
| public int getPeriodInSeconds() { | ||
| return Math.toIntExact(period / 1000); | ||
| return Math.toIntExact(period.getSeconds()); | ||
| } | ||
| } | ||
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
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
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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/somemore/global/auth/usecase/AuthQueryService.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,32 @@ | ||
| package com.somemore.global.auth.usecase; | ||
|
|
||
| import com.somemore.global.auth.jwt.domain.EncodedToken; | ||
| import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; | ||
| import com.somemore.user.domain.UserRole; | ||
| import com.somemore.user.usecase.UserQueryUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class AuthQueryService implements AuthQueryUseCase { | ||
|
|
||
| private final UserQueryUseCase userQueryUseCase; | ||
| private final RefreshTokenManager refreshTokenManager; | ||
|
|
||
| @Override | ||
| public UserRole getRoleByUserId(UUID userId) { | ||
| return userQueryUseCase.getRoleById(userId); | ||
| } | ||
|
|
||
| @Override | ||
| public EncodedToken getAccessTokenByUserId(UUID userId) { | ||
| return new EncodedToken( | ||
| refreshTokenManager.findRefreshTokenByUserId(userId) | ||
| .getAccessToken()); | ||
| } | ||
| } |
Oops, something went wrong.
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.
여기도 from과 of 어떤게 적절할 지 의견나눠보면 좋을거 같아요!