Skip to content

Conversation

@ammerss
Copy link
Contributor

@ammerss ammerss commented Apr 1, 2022

refresh 토큰으로 access 토큰이랑 refresh 토큰을 새로 발급받는다

header 입력 방식 :

key값:
Authorization

value값:
Refresh

access 토큰 쓰던거랑 비슷한데 Bearer 대신 Refresh 쓰고 토큰 입력 하면 된다.
토큰을 해독할때 무슨 토큰이였는지 구분하기 위해서다.

주의사항 :
헤더에 토큰 입력할때 access 토큰 또는 refresh 토큰 둘 중 하나만 입력해야한다. 둘다 입력하면 access 토큰만 가지고 처리된다.
access 토큰 먼저 확인하고 그걸로 예외처리한다.
access 토큰 없으면 refresh 토큰 확인하고 그걸로 예외처리한다.

@ammerss ammerss requested review from Youhoseong and ilene97 April 1, 2022 06:05
Copy link
Contributor

@Youhoseong Youhoseong left a comment

Choose a reason for hiding this comment

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

내용 확인 부탁드려요

Comment on lines +54 to +60
@GetMapping("/gen-tokens")
public ResponseEntity<?> sendTokens(Authentication authentication){
Optional<User> user = userRepository.findByPhone(authentication.getName());
TokenDto tokenDto = authenticateService.getNewTokens(user.get().getPhone());
ApiResponse message = new ApiResponse(ResultCode.OK,"Generating token success.", tokenDto);
return new ResponseEntity<>(message, HttpHeaderSetting(), HttpStatus.OK);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

authentication.getName()이 user.get().getPhone()과 같은 데이터인데 불필요한 유저 조회가 한번 더 들어가는 것 같습니다~

Copy link
Contributor

Choose a reason for hiding this comment

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

또, 귀찮겠지만 ResponseEntity는 더이상 사용하지 않고 ApiReponse만 반환하도록 했습니다 ㅎ ProductController 참고하시고

이유는 데이터 -> (감싸기) -> ApiReponse -> (또 감싸기) -> ResponseEntity 이렇게 두번씩 감쌀 필요가 없다는 생각때문입니다

Comment on lines 44 to 58
try {
String jwt = parseJwt(request);
if (jwtUtils.validateJwtToken(jwt)) {
HashMap<String, String> map = parseJwt(request);
if(map.containsKey("access")){
String jwt = map.get("access");
jwtUtils.validateJwtToken(jwt);
String username = jwtUtils.getUserNameFromJwtToken(jwt);
jwtUtils.createAuthentication(username);
}

else if(map.containsKey("refresh")){
String jwt = map.get("refresh");
jwtUtils.validateJwtRefresh(jwt);
String username = jwtUtils.getUserNameFromJwtRefreshToken(jwt);
jwtUtils.createAuthentication(username);
}
filterChain.doFilter(request, response);
Copy link
Contributor

Choose a reason for hiding this comment

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

로직이 access token 검사 후 혹시 refresh token이 있다면 refresh 토큰으로도 인증이 성공하도록 되어있는데요,

프론트쪽에서 access token과 refresh token을 동시에 사용해야할 일이 있을까요? refresh token은 최대한 사용을 자제하면서 노출을 피하고, access token을 재발급하기 위한 용도로만 사용하는 것이 맞지 않나 싶은데 의견부탁해요~~~

  1. 프론트쪽에서 access token 기반 요청 => 만료
  2. 프론트쪽에서 refresh token으로 access token 재발급 요청
  3. 프론트쪽에서 access token 기반 재요청

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