Skip to content

feat: OAuth 로그인 #1

Open
Open

Description

@KodaHye

어떤 기능인가요?

  • JWT, Spring Security, OAuth를 이용한 로그인 기능 (백엔드)

작업 상세 내용

  • Spring Security, JWT을 통한 일반 회원가입/로그인
  • OAuth 회원가입/로그인
    • Kakao
    • Google
  • 로그아웃
  • 회원 정보 수정
  • 회원 탈퇴

참고할만한 자료(선택)

Activity

  1. changed the title [-]feat: 회원가입/로그인 기능[/-] [+]feat: OAuth 로그인[/+] on Dec 16, 2024
  2. self-assigned this
    on Dec 23, 2024
  3. KodaHye commented on Dec 23, 2024

    @KodaHye
    ContributorAuthor

    2024.12.24

    • Token과 관련된 서비스 작성

    • Spring Security filter 작성

    • 자체 로그인을 진행하려 하는데, SpringSecurity에서 일반 Form Login을 기본적으로 제공하지만 JSON 형식으로 RequestBody를 받아서 로그인하는 방식은 제공하지 않기 때문에 커스텀 필터를 구현함

    • 찾아봐야 되는 부분

      • SecurityConfig 설정 부분에서 requestMatchers("주소").permitAll()을 하면 해당 주소는 어떠한 인증이 없어도 요청을 할 수 있는거 아닌지...
        • permitAll을 했을 때, 403 오류가 발생하고, csrf(AbstractHttpConfigurer::disable) 설정을 추가로 했는데 이렇게 해도 되는건지 잘 모르겠음. 뭔가 잘못된거같음

    내일 할거 목록

    • 자체 로그인/회원가입 끝내보기

    완전하게 구현하지는 못해서 커밋은 하지 않았습니다 ㅠㅠ. 흐엉.
    진전이 없네요.... ~~ 그래도 힘내고 킵 고잉~

  4. KodaHye commented on Jan 8, 2025

    @KodaHye
    ContributorAuthor

    2024/12/30

    현재 진행사항

    • MySQL 설정
    • 회원 가입 로직 완료

    궁금한 사항

    • .csrf(AbstractHttpConfigurer::disable) 이거 해줘야 post 403 오류 발생안하는 이유?
  5. KodaHye commented on Jan 8, 2025

    @KodaHye
    ContributorAuthor

    2025/01/07

    오늘 한 일

    • form login말고 JSON 형식 로그인으로 바꾸기

    SecurityConfig

    • httpBasic(AbstractHttpConfigurer::disable)
      • 뭔지 찾아보기
    • sessionManagement(sessionManagement → sessionmanagement.sessionCreationPolicy(Session.STATELESS)
      • 찾아보기
    • JSON 형식으로 로그인하기 위해서는 AbstractAuthenticationProcessiongFilter에 있는 인터페이스를 JSON에 맞게 수정해야됨
      • AbstractAuthenticationProcessingFilter 클래스 안에 doFilter를 보면

        1. requiresAuthentication을 통해 인증의 필요성을 체크하는 것을 알 수 있음

        image (1)

        • /login에 대한 POST 요청이면 RequiresAuthenticationRequestMatcher.matches에서 처리 → login에 대한 컨트롤러를 따로 만들 필요가 없음

        • RequiresAuthenticationRequestMatcher로는 AntPathRequestMatcher가 사용

        1. attemptAuthentication 실행 → Authentication 객체 반환
          • attempAuthentication
            • 추상 메서드로 AbstractAuthenticationProcessingFilter를 구현한 클래스에서 이를 구현하여 사용함
            • formLogin에서는 UserPasswordAuthenticationFilter가 사용
    • 로그인 필터 커스터마이징
      • AbstractAUthenticationProcessFilter를 상속받은 Filter 만들기
      • AuthenticationManager로는 스프링과 똑같이 ProviderManger 사용 (DaoAuthenticationProvider)
      • UserDetailsService는 JPA와 연동시킨 LoginService가 상속받아 구현
      • 우리가 DB에서 찾은 유저 정보는 UserDetails라는 객체에 저장되고, 이걸 /login POST에서 받은 password를 검증해야 됨
        • DaoAuthenticationProvider에서 해줌 (AbstractUserDetailsAuthenticationProvider)
        • password는 JsonUsernamePasswordAuthenticationFilter의 Reuqest 정보로 통해 인자로 전달해준 Authentication객체(UsernamePasswordAuthenticationToken)의 credentials에 저장되어 있음

    참고

  6. reopened this on Jan 8, 2025
  7. KodaHye commented on Jan 8, 2025

    @KodaHye
    ContributorAuthor

    2025/01/08

    오늘 한 일

    • 로그인 시 Token 발급 (RefreshToken Mysql에 저장함. 추후 수정)
      • JWTService, JWTTokenProvideHandler 작성
      • SecurityConfig 적용
  8. KodaHye commented on Jan 12, 2025

    @KodaHye
    ContributorAuthor

    2025/01/12

    오늘 한 일

    • JwtAuthenticationFilter 설정 추가
    • JwtAuthenticationFilter 테스트 진행
      • URL 요청에 대해 RefreshToken, AccessToken이 어떤 상태인지에 대해 각 각 테스트 진행

    내일(?) 할 일

    • 진짜루 카카오 OAuth 구현하기
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions