-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Feature] 리프레시 토큰 적용 #61
[Feature] 리프레시 토큰 적용 #61
Conversation
로컬 테스트 용도
- chart 엔티티와 일대일 연관관계 설정
- 환자 id로 일지 전체 조회 함수 구현
- 환자 id로 일기 전체 조회 기능 구현
- default_page_size 선언
- 단순 조회 대신 토큰값 비교 후 boolean 값 반환
- 해당 액세스 토큰이 블랙리스트에 등록되어 있는지 확인
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.
수고하셨습니다!!
.authenticationEntryPoint((request, response, authException) -> { | ||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "인증 실패"); | ||
})); | ||
.addFilterBefore(new ExceptionHandlingFilter(), UsernamePasswordAuthenticationFilter.class) |
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.
이런 식이면? JWT필터 -> exception필터 -> username필터? 순으로 생성되어서 jwt필터에서 생성된 예외가 exception으로 안넘어가지않나욧...?!
그럼 jwt필터에서 생긴 예외가 위로? 가면 예외 필터로 가지 않는? 건가욧?
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.
exception 필터 -> Jwt 필터 -> username 필터 순으로 들어갑니다!
그래서 jwt 필터에서 오류가 나면 exception 필터에서 오류를 처리할 수 있어요!
.authenticationProvider(baseAuthenticationProvider()) | ||
.authorizeHttpRequests((authorize) -> { | ||
authorize | ||
.requestMatchers(HttpMethod.POST, |
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.
post 지정 좋네요 ㅅㅅ
@RequiredArgsConstructor | ||
public class RedisService { | ||
|
||
private static final String REFRESH_TOKEN_PREFIX = "refresh-token"; |
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.
이부분도 application.yml로 뽑아서 하는건 어떠신지요?
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.
redisService 내에서만 쓰는 상수라 클래스 내에 선언해두었습니다!
application.yml로 뽑아서 사용하면 어떤 장점이 있을까요??
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.
너무 수고하셨어요! 잘 몰라서 궁금한 점들을 적어봤습니다.
|
||
if (token != null) { | ||
try { | ||
//jwtProvider.validateToken(token); | ||
Authentication authentication = jwtProvider.getAuthentication(token); | ||
SecurityContextHolder.getContext().setAuthentication(authentication); | ||
} catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException | | ||
SignatureException | SecurityException | IllegalArgumentException ex) { | ||
throw ex; |
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.
ex보단 에러명을 지정해서 던져주는 건 어떠신가요? 원래 저희가 사용하던 ApplicationError 대신 이걸 사용하신 이유가 있을까요?
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.
토큰 검증에서 발생하는 오류는 저희가 직접 던지는 오류가 아니에요!
그래서 jwt 관련 오류가 발생했을 때를 대비해서 짠 로직입니다.
근데 혜연님 말씀대로 굳이 에러 그대로 throw할 필요는 없는 것 같아요. 수정하겠습니다!
return ResponseEntity.ok().header(authHeader, token.accessToken()).body(token); | ||
} | ||
|
||
@PostMapping("/renew") |
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.
이건 어떤 부분인가요? 제가 코드를 이해를 잘 못했습니다. accesstoken을 refreshtoken으로 바꿔주는 건가요..?
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.
액세스 토큰 유효시간이 지났을 때 리프레시 토큰으로 새로운 액세스 토큰을 발급하는 api입니다!
|
||
public JwtProvider(@Value("${spring.jwt.secret}") String secret, | ||
BaseUserDetailsService baseUserDetailsService) { | ||
BaseUserDetailsService baseUserDetailsService, RedisService redisService) { | ||
this.secretKey = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"); |
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.
이 부분은 경미님이 하신 건 아닌 것 같지만 의견 남겨봅니다. HmacSHA256 같은 값은 변경 될 수 있으니 상수로 나두는게 어떨까요?
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.
옹 좋네요 제가 상수처리 해놓을게요
import org.springframework.data.redis.core.RedisTemplate; | ||
|
||
@SpringBootTest | ||
public class RedisTest { |
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.
테스트까지! 최곱니다!
.clientOptions( | ||
ClientOptions.builder() | ||
.socketOptions(SocketOptions.builder() | ||
.connectTimeout(Duration.ofSeconds(10)) // 연결 타임아웃 설정 |
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.
10초로 설정하신 이유가 있을까요? 그냥 궁금증입니다.
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.
보통 api 연결 테스트를 10초로 하더라구요
별 이유는 없습니다...ㅋㅋㅋㅋ
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.
완벽합니다~!!! 정말 잘해주신 거 같아요!!!
🔥 관련 이슈
close: #60 #62
📝 작업 상세 설명
⭐ 리뷰 요구 사항
+380줄이긴 한데 인텔리제이 자동 정렬 때문에 뻥튀기 된겁니다;ㅎㅎ