devHudi / hudi.blog

개인 블로그
https://hudi.blog
MIT License
17 stars 3 forks source link

refresh-token-in-spring-boot-with-redis/ #97

Open utterances-bot opened 6 months ago

utterances-bot commented 6 months ago

Spring Boot와 Redis를 사용하여 Refresh Token 구현하기

https://hudi.blog/refresh-token-in-spring-boot-with-redis/

uHan2 commented 6 months ago

안녕하세요 글 잘 읽었습니다. 저도 마찬가지로 공부하는 입장에서 궁금한게 있어 댓글 남겨봅니다.

        valueOperations.set(refreshToken.getRefreshToken(), refreshToken.getMemberId());

redis에 리프레쉬 토큰 저장하는 코드에서 키값에 리프레쉬 토큰이 들어가고 밸류값에 아이디값이 들어가는거 같은데

리프레쉬토큰 만료 체크라든지 등의 이유로 밸류값에 리프래쉬 토큰을 저장해야하지 않을까요??

uHan2 commented 6 months ago

아 레디스의 TTL을 만료기간과 동일하게 해서 토큰 자체를 삭제시키면 상관없긴 하겠녜요!

devHudi commented 6 months ago

@uHan2 네 실제 구현은 모두 다르겠지만, 예제에서 사용된 리프레시 토큰은 의미나 데이터를 담고 있지 않은 UUID를 사용했으므로 그 자체로 만료 검증은 불가능하며,

@RedisHash(value = "refreshToken", timeToLive = 60)

와 같이 TTL을 임의로 설정했으므로, 이것이 만료기간이라고 보시면 될듯합니다.

gyunseo commented 4 months ago

좋은 글 잘 읽고 갑니다! 이 글 덕에 troubleshooting 해결하고 갑니다.

DJDrama commented 2 months ago

글이 매우 도움 됩니다! 저도 궁금한 것이, Key가 RefreshToken이고 value가 UserDetails인 경우, 사용자가 이전 refreshToken으로 새로운 토큰을 계속해서 발급받을 수 있지 않을까요?

실제 production에서는 어떻게 해야할까요?! 악의적으로 계속 발급받는 경우가 발생할 수 있지 않을까 해서 질문 드립니다~!

DJDrama commented 2 months ago

아 생각해보니 아니네요. 어차피 클라이언트에서는 새로운 토큰을 발급받는거지 refreshToken을 발급받는게 아니다보니 ㅎㅎ 좋은 글 감사합니다! ㅎㅎ