Git Product home page Git Product logo

jib's People

Contributors

ekgns33 avatar hayeon17kim avatar myeongkwonhwang avatar

Stargazers

 avatar

Watchers

 avatar  avatar

jib's Issues

인증 기능 개선: JWT refresh token

Description

Problem

  • 현재 로그인 기능은 access token만을 발급하여 client에 전달하여 로그인을 유지하고 있습니다.
  • refresh token은 존재하지 않고 access token만을 가지고 있기 때문에, access token의 유효기간이 1일로 되어 있습니다.
  • 이 경우 access token이 탈취되어 악용될 가능성이 높습니다.
  • 만약 access token의 기한을 짧게 잡는다면 그 시간이 지날 때마다 로그인이 풀릴 것입니다.

Solution

  • access token의 유효기간을 1일에서 30분으로 변경하였습니다.

  • 유효기간이 2주인 refresh token을 발급하여 redis에 저장할 것입니다.

  • refresh token의 저장 장소는 redis로 결정하였습니다.

    • refresh token은 유효시간이 있습니다. 유효시간이 지나면 바로 삭제 처리를 해주는 redis를 사용하면 따로 유효시간을 확인하고 삭제하는 코드를 작성하지 않아도 됩니다.
    • 로그인 유지를 위해서는 access token이 만료될 때마다 지속적으로 refresh token 을 조회해야 합니다. 이것이 빈번하게 일어나기 때문에, 비용이 큰 rdb보다는 비교적 조회 시간이 빠른 캐시저장소를 사용함으로써 비용을 아끼고자 하였습니다.

전체적인 로직은 다음과 같습니다.

  1. 사용자 로그인 요청
  2. 사용자 확인 후, access token과 refresh token 발급
  3. refresh token을 redis에 저장
  4. 클라이언트는 access token 과 refresh token을 로컬스토리지/쿠키 등 저장소에 저장한다.
  5. 클라이언트는 로그인 이후의 요청에는 항상 발급받은 access token 을 헤더에 함께 보내 로그인을 유지한다.
  6. 유효기간(30분)이 지나면 서버는 토큰이 유효하지 않다는 응답을 보낼 것이다.
  7. 해당 응답을 받은 클라이언트는 저장되어 있던 refresh token 과 함께 서버에 토큰 재발급 요청을 보낸다.
  8. 토큰 재발급 요청을 받은 서버는 redis에 refresh token 정보가 존재하는 지 확인 후 access token 을 재발급해준다.
  9. 로그아웃 시, redis에 refresh token 정보를 삭제한다.

Process

토큰 발급

  • TokenProvider의 generateToken() 메서드에서 refresh token 발급
  • refresh token 과 access token을 담을 TokenDto 작성
  • token 정보(유효시간 등)를 가져올 TokenType enum 작성

authenticate 시 토큰 처리

  • UserLoginService.authenticate() 메서드에서 TokenProvider의 generateToken을 호출해서 TokenDto를 받는다.
  • 이때, AccessToken은 리턴해서 authenticate를 호출한 곳 (login, signup) 에서 response로 access token을 사용하도록 만든다.
  • refresh token은 redis에 저장한다. 이를 위해 refreshToken entity와 refreshTokenRedisRepository를 작성한다.

로그인 시 accessToken 검증, refreshToken 조회

  • access token 이 유효하지 않다면, redis에서 refresh token을 조회한다.
    • JwtAuthenticationFilter에서 분기처리
    • TokenExpiredException 정의
    • ExceptionHandler에서 해당 Exception에 따른 응답 정의
  • refresh token이 없다면, 프론트에서 로그아웃 처리를 하도록 적절한 응답을 준다.
  • refresh token이 있다면, access token을 생성하여 발급한다.

로그아웃 시 redis에 refresh token 정보 삭제

  • 로그아웃 기능 추가
  • 로그아웃 시 refresh token 삭제

일반 회원가입

Description

일반 회원가입 기능을 추가한다.

Process

  • 일반 회원가입
  • 회원가입 테스트 코드 작성 (성공, 실패)

파일 업로드

스토리지를 S3로 하는 파일 업로드 기능을 구현한다.

목적지 목록 조회 시 페이징 처리

Problem

현재 목적지 목록 조회 시 페이징 처리가 되어 있지 않아 조회 시간이 오래 걸린다.

Solution

  • 목적지 목록 조회 시 paging 처리를 한다.
  • 한 페이지당 20개를 기본값으로 설정한다.

Progress

  • Controller
  • Service
  • Repository

Create Issue, PR Template

Problem

현재 Issue와 PR의 정해진 형식이 없어,
가독성이 좋지 않고, 빠른 작성이 어려운 단점이 있다.

Solution

이에 Issue와 PR 템플릿을 만들어 효율적인 협업이 가능하도록 한다.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.