-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/issue#61 #62
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
base: dev
Are you sure you want to change the base?
Feature/issue#61 #62
Conversation
Youhoseong
left a comment
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.
내용 확인 부탁드려요
| @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); | ||
| } |
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.
authentication.getName()이 user.get().getPhone()과 같은 데이터인데 불필요한 유저 조회가 한번 더 들어가는 것 같습니다~
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.
또, 귀찮겠지만 ResponseEntity는 더이상 사용하지 않고 ApiReponse만 반환하도록 했습니다 ㅎ ProductController 참고하시고
이유는 데이터 -> (감싸기) -> ApiReponse -> (또 감싸기) -> ResponseEntity 이렇게 두번씩 감쌀 필요가 없다는 생각때문입니다
| 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); |
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.
로직이 access token 검사 후 혹시 refresh token이 있다면 refresh 토큰으로도 인증이 성공하도록 되어있는데요,
프론트쪽에서 access token과 refresh token을 동시에 사용해야할 일이 있을까요? refresh token은 최대한 사용을 자제하면서 노출을 피하고, access token을 재발급하기 위한 용도로만 사용하는 것이 맞지 않나 싶은데 의견부탁해요~~~
- 프론트쪽에서 access token 기반 요청 => 만료
- 프론트쪽에서 refresh token으로 access token 재발급 요청
- 프론트쪽에서 access token 기반 재요청
refresh 토큰으로 access 토큰이랑 refresh 토큰을 새로 발급받는다
header 입력 방식 :
key값:
Authorization
value값:
Refresh
access 토큰 쓰던거랑 비슷한데 Bearer 대신 Refresh 쓰고 토큰 입력 하면 된다.
토큰을 해독할때 무슨 토큰이였는지 구분하기 위해서다.
주의사항 :
헤더에 토큰 입력할때 access 토큰 또는 refresh 토큰 둘 중 하나만 입력해야한다. 둘다 입력하면 access 토큰만 가지고 처리된다.
access 토큰 먼저 확인하고 그걸로 예외처리한다.
access 토큰 없으면 refresh 토큰 확인하고 그걸로 예외처리한다.