Skip to content

🔀 :: (#316) - OAuth 로그인에 state·PKCE 적용 및 callback 검증 - #391

Merged
minwoo0708 merged 6 commits into
developfrom
feature/#316-oauth-state-pkce
Oct 11, 2026
Merged

minwoo0708 merged 6 commits into
developfrom
feature/#316-oauth-state-pkce

Conversation

@minwoo0708

@minwoo0708 minwoo0708 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ 백엔드 배포 전 머지 금지
인가 요청에 code_challenge를 보내면 DataGSM이 토큰 교환 때 code_verifier를 요구합니다. 서버(TokenReqDto·SignInServiceImpl)가 codeVerifier를 받아 넘기도록 배포되기 전에 머지하면 로그인이 실패합니다. 서버 배포를 확인한 뒤 Ready for review로 바꾸겠습니다.

💡 개요

OAuth 로그인 요청과 callback을 같은 일회성 트랜잭션으로 묶어 검증합니다. 요청마다 state와 PKCE(S256) code verifier를 만들고, callback의 경로·state를 확인한 뒤 verifier를 서버 로그인 요청에 함께 보냅니다.

🔗 관련 이슈

Close #316

📃 작업내용

트랜잭션 (OAuthTransaction, 새 파일)

  • 요청마다 Random.secure()로 32바이트 state·code verifier 생성 (base64url 43자)
  • code_challenge = SHA-256(verifier)의 base64url(패딩 없음), code_challenge_method=S256
  • callback 검증: scheme·host·path가 com.washer.v2://auth/callback과 정확히 같고, state가 일치하고, code가 있어야 통과

로그인 흐름 (LoginNotifier)

  • 인가 URL에 state, code_challenge, code_challenge_method 추가
  • callback을 받으면 트랜잭션을 먼저 비워 같은 callback을 재사용할 수 없게 함
  • 브라우저 인증부터 서버 로그인 완료까지 실행 플래그로 보호해, 진행 중에는 새 로그인을 시작하지 않음 (finally에서 해제)
  • 검증에 실패하면 서버에 보내지 않고 기존 로그인 실패 문구로 안내
  • 브라우저를 닫은 취소는 기존처럼 오류 없이 종료
  • 테스트를 위해 브라우저 호출을 webAuthenticatorProvider로 분리하고, 환경 설정을 AppEnvironment.instance 대신 appEnvironmentProvider로 읽음

서버 요청 (LoginRequest, AuthRepository)

  • codeVerifier 선택 필드 추가 (null이면 JSON에서 생략), build_runner로 생성 파일 갱신

기타

  • debug 요청 로그(sanitizeDioLog)에서 authCode·codeVerifier(code_verifier)를 가림
  • AppEnvironment.test()에 OAuth 설정 파라미터 추가 (테스트 전용)
  • lib/features/auth/README.md 로그인 흐름·구조·주의사항 갱신

🔍 테스트 방법

  • flutter analyze --no-fatal-infos 이슈 없음, flutter test 전체 340개 통과
  • test/features/auth/oauth_transaction_test.dart: RFC 7636 부록 B 값으로 S256 challenge 확인, 요청마다 다른 state·verifier, 인가 URL 파라미터, state 누락·불일치·잘못된 scheme/host/path·code 누락 거부
  • test/core/dio_log_sanitization_test.dart: 로그인 요청 본문(Map·JSON·snake_case)에서 인가 코드와 verifier 원문이 로그에 남지 않음
  • test/features/auth/login_provider_test.dart: 정상 로그인 시 보낸 challenge와 verifier 일치, 위조 state 거부, 이전 트랜잭션 callback 재사용 거부, 로그인마다 다른 verifier, 진행 중 로그인 덮어쓰기 방지, 서버 로그인 응답 대기 중 재진입 방지, 브라우저 닫기 취소
  • 실기기 로그인은 서버 배포 후 확인 필요 (아직 미확인)

🙋‍♂️ 질문사항

  • 개선할 점, 오타, 코드에 이상한 부분이 있다면 Comment 달아주세요.
  • 서버 요청 사항: TokenReqDto에 선택 필드 codeVerifier를 추가하고, 값이 있으면 exchangeCodeForToken(authCode, redirectUri, codeVerifier)를 호출해야 합니다(DataGSM OAuth SDK에 있는 오버로드). 필드를 선택으로 두면 구버전 앱도 그대로 로그인됩니다.

✅ 체크리스트

  • 코드가 정상적으로 컴파일되고 실행되는지 확인했습니다.
  • 불필요한 코드가 없는지 확인했습니다.
  • 코드 스타일 가이드를 준수했습니다.
  • 기존 기능이 정상적으로 작동하는지 확인했습니다. (서버 배포 후 실기기 로그인 확인 필요)

minwoo0708 and others added 2 commits October 7, 2026 23:07
@minwoo0708
minwoo0708 marked this pull request as ready for review October 7, 2026 23:56

@inryeok-bot inryeok-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 결과

변경된 11개 파일을 검토했습니다. 인라인 관찰 1개를 게시했습니다.

심각도 개수
치명적 0
높음 0
중간 1
낮음 0

유형: 필수 수정 0, 수정 권장 1, 제안 0, 확인 질문 0, 좋았던 점 0

주요 관찰

  • 수정 권장 · MEDIUM 서버 로그인 완료 전 동시 실행 방지가 해제됩니다

검토한 head: ff2a7eeadd68 · 최신 head는 /review로 검토하세요.

minwoo0708 and others added 2 commits October 11, 2026 15:33
@minwoo0708
minwoo0708 merged commit 85c711b into develop Oct 11, 2026
2 checks passed
@minwoo0708
minwoo0708 deleted the feature/#316-oauth-state-pkce branch October 11, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants