Skip to content

Conversation

@jsoonworld
Copy link
Member

📄 Work Description

표준적인 JWT 키 생성 방식 도입을 시도했으나, 이로 인해 기존 사용자들의 토큰이 만료되지 않았음에도 재로그인을 해야 하는 불편함이 발생할 수 있음을 확인했습니다.

사용자 경험을 최우선으로 고려하여, 더 나은 방식(듀얼 키 등)의 도입은 추후 과제로 남겨두고, 우선 안정성이 검증된 과거의 단일 키 방식으로 롤백하는 것을 결정했습니다.

특히, 과거 시스템이 secret-keyBase64 인코딩하여 사용했던 고유한 로직을 그대로 복원하여 완전한 하위 호환성을 보장하는 데 중점을 두었습니다.

1. feat: JWT 시크릿 키 Base64 인코딩 방식 복원

  • ValueConfig.java: @PostConstruct를 사용하여 application.yml에서 읽어온 secret-key를 Base64로 인코딩하는 과거 로직을 복원했습니다. 이를 통해 모든 토큰이 일관된 방식으로 서명될 수 있는 기반을 마련했습니다.

2. refactor: JwtProvider를 단일 키 처리 방식으로 단순화

  • JwtProvider.java: New/Old 듀얼 키 관리 로직을 모두 제거하고, ValueConfig에서 처리된 최종 키를 받아 사용하는 단일 secretKey 필드만 남겼습니다. 토큰 생성(generateToken) 및 검증(parseClaims) 로직이 모두 이 단일 키를 사용하도록 수정하여 코드를 단순화하고 오류 발생 가능성을 줄였습니다.

3. refactor: JWT 관련 에러 코드 및 예외 처리 통일

  • JwtErrorCode.java: 듀얼 키 마이그레이션 시도 과정에서 추가되었으나 현재 사용되지 않는 에러 코드들을 제거하고, 메시지를 명확하게 정리했습니다.
  • AuthService.java, User.java: 정리된 JwtErrorCode에 맞춰 예외 처리 부분을 INVALID_TOKEN으로 통일하여 일관성을 확보했습니다.

💬 To Reviewers

  • 이전 토큰과 새로 발급받은 토큰이 모두 정상적으로 검증되는지 확인 부탁드립니다.
  • 키 생성 로직이 과거 방식(ValueConfig에서 인코딩)과 현재 JwtProvider의 초기화 로직이 어떻게 연계되는지 중점적으로 봐주시면 감사하겠습니다.
  • 표준 방식 도입을 보류하고 롤백을 결정한 트레이드오프에 대해 함께 논의하면 좋겠습니다.

⚙️ ISSUE

@jsoonworld jsoonworld requested a review from Copilot July 15, 2025 01:11
@jsoonworld jsoonworld self-assigned this Jul 15, 2025
@jsoonworld jsoonworld added ♻️ refactor 코드 리팩토링 ex) 형식변경 🦊장순🦊 labels Jul 15, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR rolls back the JWT key generation and verification logic to the previous single-key approach with Base64-encoded secrets for full backward compatibility. Main changes:

  • Restore Base64 encoding of secretKey in ValueConfig
  • Simplify JwtProvider to use a single secretKey and centralize exception handling
  • Clean up and unify JWT error codes, and update exception usage in User and AuthService

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ValueConfig.java Added @PostConstruct to Base64-encode the loaded secretKey
JwtProvider.java Removed dual-key logic, centralized parseClaims exception mapping
JwtErrorCode.java Removed unused codes, renamed and standardized error messages
User.java Switched thrown error from INVALID_JWT_TOKEN to INVALID_TOKEN
AuthService.java Updated orElseThrow to use INVALID_TOKEN for missing user
Comments suppressed due to low confidence (4)

src/main/java/org/terning/terningserver/common/config/ValueConfig.java:32

  • Consider adding integration tests to verify that tokens generated before and after this Base64 encoding change remain valid, ensuring backward compatibility.
        secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes(StandardCharsets.UTF_8));

src/main/java/org/terning/terningserver/auth/jwt/exception/JwtErrorCode.java:24

  • [nitpick] You've removed the '[JWT ERROR]' prefix and changed field 'rawMessage' to 'message'. Ensure downstream code that logs or returns error messages still includes necessary context or reintroduce a standard prefix if required for consistency.
    private final String message;

src/main/java/org/terning/terningserver/auth/application/AuthService.java:114

  • [nitpick] Throwing INVALID_TOKEN for a missing user record may obscure the real issue; consider a distinct error code like USER_NOT_FOUND or INVALID_USER_ID for clarity.
                .orElseThrow(() -> new JwtException(JwtErrorCode.INVALID_TOKEN));

src/main/java/org/terning/terningserver/auth/jwt/JwtProvider.java:92

  • The ExpiredJwtException type is referenced but not imported; add an import for io.jsonwebtoken.ExpiredJwtException (and similarly for MalformedJwtException and UnsupportedJwtException) to avoid compile errors.
        if (e instanceof ExpiredJwtException) {

@jsoonworld jsoonworld merged commit e05c6b8 into develop Jul 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

♻️ refactor 코드 리팩토링 ex) 형식변경 size/M 🦊장순🦊

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: JWT 키 생성 및 검증 로직을 이전 방식으로 롤백

2 participants