-
Notifications
You must be signed in to change notification settings - Fork 0
[#129]; feat: 표준 토큰 응답 적용 및 타입클레임 추가 #130
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
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1fa766
[#129]; feat(auth): 관련 dto에 tokenType 필드 추가
seulnan e5b29fd
[#129]; refactor(auth): 토큰 예외 메시지 상수화
seulnan 5b138be
[#129]; fix!(auth): jwtTokenProcessor에서 Bearer 접두사 유무 허용
seulnan e0cf3b8
[#129]; refactor(auth): 토큰예외메시지 상수화 적용
seulnan b22e4b9
[#129]; feat(auth): /refresh-token에서 Authorization 헤더 무시
seulnan 5c0de59
[#129]; test(auth): 타입 불일치·접두사 호환·tokenType 클레임 테스트 추가
seulnan 43ad3c2
[#129]; docs(openapi): v1.1.0으로 업데이트
seulnan daf8a0d
[#129]; refactor(jwt): buildMap 사용으로 claims 생성 단순화 및 성능 개선
seulnan 6bb15c7
[#129]; refactor(auth): tokenType 클레임 비교를 대소문자 무시 → 엄격 비교로 정렬
seulnan 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
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
8 changes: 8 additions & 0 deletions
8
...ain/kotlin/com/yourssu/scouter/common/implement/support/exception/InvalidTokenMessages.kt
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.yourssu.scouter.common.implement.support.exception | ||
|
|
||
| object InvalidTokenMessages { | ||
| const val INVALID_TOKEN: String = "유효한 토큰이 아닙니다." | ||
| const val NOT_REFRESH_TOKEN: String = "리프레시 토큰이 아닙니다." | ||
| const val NOT_ACCESS_TOKEN: String = "액세스 토큰이 아닙니다." | ||
| const val LOGGED_OUT: String = "로그아웃되었습니다." | ||
| } |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import com.yourssu.scouter.common.implement.domain.authentication.Token | |||||
| import com.yourssu.scouter.common.implement.domain.authentication.TokenProcessor | ||||||
| import com.yourssu.scouter.common.implement.domain.authentication.TokenType | ||||||
| import com.yourssu.scouter.common.implement.support.exception.InvalidTokenException | ||||||
| import com.yourssu.scouter.common.implement.support.exception.InvalidTokenMessages | ||||||
| import io.jsonwebtoken.Claims | ||||||
| import io.jsonwebtoken.JwtException | ||||||
| import io.jsonwebtoken.Jwts | ||||||
|
|
@@ -32,11 +33,12 @@ class JwtTokenProcessor( | |||||
| val issueDate: Date = convertToDate(issueTime) | ||||||
| val key: String = jwtProperties.findTokenKey(tokenType) | ||||||
| val expiredHours: Long = jwtProperties.findExpiredHours(tokenType) | ||||||
| val claimsWithTokenType: Map<String, Any> = HashMap(privateClaims).plus("tokenType" to tokenType.name) | ||||||
|
|
||||||
| return TOKEN_PREFIX + Jwts.builder() | ||||||
| return Jwts.builder() | ||||||
| .issuedAt(issueDate) | ||||||
| .expiration(Date(issueDate.time + expiredHours * 60 * 60 * 1000L)) | ||||||
| .claims(privateClaims) | ||||||
| .claims(claimsWithTokenType) | ||||||
| .signWith(Keys.hmacShaKeyFor(key.toByteArray(StandardCharsets.UTF_8))) | ||||||
| .compact() | ||||||
| } | ||||||
|
|
@@ -48,33 +50,46 @@ class JwtTokenProcessor( | |||||
| } | ||||||
|
|
||||||
| override fun decode(tokenType: TokenType, token: String): Claims? { | ||||||
| validateBearerToken(token) | ||||||
| val pureToken = findActualToken(token) | ||||||
|
|
||||||
| return parseToClaims(tokenType, token) | ||||||
| } | ||||||
| // 1) 요청된 타입의 키로 먼저 검증 | ||||||
| val requestedKey: String = jwtProperties.findTokenKey(tokenType) | ||||||
| parseWithKey(requestedKey, pureToken)?.let { claims -> | ||||||
| val actualType: String? = claims["tokenType"] as? String | ||||||
| if (actualType != null && !actualType.equals(tokenType.name, ignoreCase = true)) { | ||||||
|
||||||
| if (actualType != null && !actualType.equals(tokenType.name, ignoreCase = true)) { | |
| if (actualType != null && actualType != tokenType.name) { |
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
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.
Creating a new HashMap and then calling plus() is inefficient. Consider using
privateClaims + ("tokenType" to tokenType.name)orbuildMap { putAll(privateClaims); put("tokenType", tokenType.name) }for better performance.