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

Refactor: token과 유저 정보를 쿠키에 담아 반환하도록 수정 #64

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

wkdehdgk159
Copy link
Contributor

No description provided.

@wkdehdgk159 wkdehdgk159 self-assigned this Jan 16, 2024
Copy link
Collaborator

@mixedtape mixedtape left a comment

Choose a reason for hiding this comment

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

인증이 헤더 토큰에서 쿠키로 바뀌었군요 고생하셨습니다

Cookie cookie = new Cookie(JWT_COOKIE_NAME, jwtToken);
cookie.setPath("/");
cookie.setMaxAge((int) EXPIRED_TIME);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 한번도 써본 적 없는데 jwt 쿠키에는 설정해도 좋겠다는 생각이 드네요

Copy link
Member

@EUNCHAEv1006 EUNCHAEv1006 left a comment

Choose a reason for hiding this comment

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

쿠키!

String token = jwtUtil.createToken(requestDTO.getUsername());
response.setHeader(JwtUtil.AUTHORIZATION_HEADER, token);
Cookie tokenCookie = jwtUtil.createTokenCookie(requestDTO.getUsername());
Cookie userInfoCookie = jwtUtil.createUserInfoCookie(userInfo);
Copy link
Member

Choose a reason for hiding this comment

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

tokenCookie.setPath("/~~"); 같이 쿠키의 경로를 지정해주는 건 어떨까요?

Cookie userInfoCookie = jwtUtil.createUserInfoCookie(userInfo); userInfoCookie.setPath("/api"); 이런 느낌?

누출도 최소화해주고 범위도 제한해주기 때문에 보안적인 측면에서 이렇게하는게 좀 더 나을 것 같은데, 어떻게 생각하시나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

좋은 의견이라고 생각합니다!

@@ -30,7 +35,14 @@ public class JwtUtil {
public static final String AUTHORIZATION_HEADER = "Authorization";

// Token 식별자
public static final String BEARER_PREFIX = "Bearer ";
public static final String BEARER_PREFIX = "Bearer%";
Copy link
Member

Choose a reason for hiding this comment

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

저는 이 때 까지 "Bearer "을 사용했는데, 왜 상수를 Bearer%로 설정하셨는지 알 수 있을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

쿠키 값에는 몇가지 특수문자가 들어갈 수 없는데 그 중 하나가 공백이더라구요.
Bearer을 안 넣어주는 방법, 공백을 인코딩해서 %20으로 바꾸는 방법 등등이 있었는데 substring 7 을 최대한 바꾸고 싶지 않아 저렇게 수정했습니다.

Copy link
Member

@EUNCHAEv1006 EUNCHAEv1006 left a comment

Choose a reason for hiding this comment

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

뭐야 왜 승인이 아니지

@wkdehdgk159 wkdehdgk159 merged commit b4b9440 into dev Jan 16, 2024
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.

3 participants