Skip to content
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

[Mod] token 유효성 응답 수정 #163

Merged
merged 2 commits into from
Mar 5, 2025
Merged

[Mod] token 유효성 응답 수정 #163

merged 2 commits into from
Mar 5, 2025

Conversation

jjjh02
Copy link
Contributor

@jjjh02 jjjh02 commented Mar 5, 2025

응답 형식

  1. 유효하지 않은 accesstoken
    accessToken != null && jwtTokenProvider.isTokenValid(accessToken)
{
    "timestamp": "2025-03-05T01:34:52.208+00:00",
    "status": 403,
    "error": "Forbidden",
    "path": "/schedule/show"
}
  1. 유효하지 않은 refreshtoken
    refreshToken != null 후, checkRefreshTokenAndReIssueAccessToken에서 확인
{
    "timestamp": "2025-03-05T01:35:29.041+00:00",
    "status": 401,
    "error": "Unauthorized",
    "path": "/schedule/show"
}

@jjjh02
Copy link
Contributor Author

jjjh02 commented Mar 5, 2025

https://github.com/DevKor-github/OnTime-back/pull/162와 다른점은 경우를
유효하지 않은 accesstoken, 유효하지 않은 refreshtoken으로만 나누어져있다는 것과
accessToken != null && jwtTokenProvider.isTokenValid(accessToken)의 경우에서 accessToken != null를 한번 더 확인하고 넘어간다는 것입니다.

@jjjh02 jjjh02 requested a review from JunbeomKoreaUniv March 5, 2025 01:46
return;
}

if (refreshToken != null) {
checkRefreshTokenAndReIssueAccessToken(response, refreshToken);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

두 if문 순서 바꾸면 좋을 것 같아요.
모든 요청에 대해서 헤더에 엑세스토큰만 담는건 확실한데
엑세스토큰 재발급이 필요한 경우에는 리프레시랑 엑세스토큰을 같이 담는 경우도 있을 수 있거든요.

일단 그래도 위 경우는 드문 경우이기 때문에 코드 자체는 이 정도면 좋은 것 같아서 따로 수정하실 필요는 없을 것 같긴합니다.
나중에 제가 만료시간쪽 검토하면서 코드 리팩토링해보겠습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이 부분은 순서를 바꾸는게 더 적합하다는 의견에 동의하는데 지금 제가 바꿔서 반영해도 될까요?

Copy link
Contributor

Choose a reason for hiding this comment

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

넵 그렇게 해주시면 감사하겠습니다~

@@ -158,7 +158,7 @@ public boolean isTokenValid(String token) {
return true;
} catch (Exception e) {
log.error("유효하지 않은 토큰입니다. {}", e.getMessage());
throw new InvalidTokenException("유효하지 않은 토큰입니다.");
return false;
Copy link
Contributor

@JunbeomKoreaUniv JunbeomKoreaUniv Mar 5, 2025

Choose a reason for hiding this comment

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

여기 return false 말고 원래처럼 Exception날리되 엑세스 만료와, 리프레시 만료 Exception을 다르게 날리고
try catch구문에서 catch문을 2개 쓰면 조금 더 완결성 있어질 것 같은데

저도 이 아이디어가 실제로 작동할지 확실한 건 아니여서 나중에 제가 만료시간쪽 검토하면서 리팩토링 해보겠습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 알겠습니다!!

if (refreshToken != null) {
checkRefreshTokenAndReIssueAccessToken(response, refreshToken);
if (accessToken != null && jwtTokenProvider.isTokenValid(accessToken)) {
checkAccessTokenAndAuthentication(request, response, filterChain);
Copy link
Contributor

Choose a reason for hiding this comment

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

순서 변경해주신거 확인했습니다. 굉장히 수고 많으셨습니다~

@JunbeomKoreaUniv JunbeomKoreaUniv merged commit 6dd3459 into main Mar 5, 2025
2 checks passed
@JunbeomKoreaUniv JunbeomKoreaUniv deleted the mod/jwt2 branch March 5, 2025 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants