Skip to content

fix: Google OAuth 스코프 누락 수정#23

Merged
Kimgyuilli merged 4 commits into
mainfrom
fix/error-573d580-20260408092201
Apr 8, 2026
Merged

fix: Google OAuth 스코프 누락 수정#23
Kimgyuilli merged 4 commits into
mainfrom
fix/error-573d580-20260408092201

Conversation

@Kimgyuilli

@Kimgyuilli Kimgyuilli commented Apr 8, 2026

Copy link
Copy Markdown
Owner

Google OAuth scope mismatch 대응

배경

  • 2026-04-08 09:21:45 UTC GET /api/calendar/calendars 요청에서 RefreshError
  • 에러 메시지: invalid_scope: Bad Request

기존 PR 설명처럼 calendar.readonly 누락 문제가 아니라, 저장된 오래된 Google refresh token과 현재 앱이 사용하는 scope 집합이 어긋나면서 refresh 단계에서 invalid_scope가 발생하는 문제였습니다.

원인

  • build_credentials()에서 최신 SCOPES 전체를 refresh 요청에도 강제로 사용하고 있었음
  • 기존 사용자 중 과거에 더 좁은 Google 권한으로 동의한 refresh token이 남아 있을 수 있음
  • 이 상태에서 최신 scope 집합으로 refresh를 시도하면 invalid_scope가 발생함

변경 내용

  • backend/app/auth/service.py
    • refresh 시 최신 SCOPES를 강제하지 않도록 build_credentials() 수정
    • Google scope mismatch 감지 헬퍼 추가
  • backend/app/auth/dependencies.py
    • invalid_scope 발생 시 저장된 Google access/refresh token 제거
    • 401 google_reconnect_required 응답으로 재연결 필요 상태를 명확히 반환
  • backend/app/core/background_sync.py
    • 백그라운드 Gmail 동기화에서도 동일한 scope mismatch 처리 적용
    • stale Google 토큰을 유지한 채 반복 실패하지 않도록 연결 해제
  • frontend/src/lib/api.ts
    • google_reconnect_required 응답 시 Google 재연결 안내 토스트 표시

테스트 보강

  • backend/tests/test_auth_dependencies.py
    • 일반 refresh 실패와 invalid_scope 분기 분리 검증
  • backend/tests/services/test_background_sync.py
    • background sync에서 invalid_scope 발생 시 연결 해제 검증
  • backend/tests/routers/test_auth.py
    • /auth/callback 신규 생성/기존 유저 업데이트/실패 분기
    • /auth/me 슬라이딩 세션 갱신 여부
    • auth 라우터의 연결 상태 응답 경계 케이스

검증

  • ./.venv/bin/ruff check .
  • ./.venv/bin/pytest
  • pnpm lint
  • pnpm test
  • pnpm build

참고:

  • pnpm build는 최초 1회 Google Fonts 네트워크 접근 제한으로 실패했고, 제한 해제 후 재실행하여 정상 통과했습니다.

커밋

  • fb7072c fix: handle Google OAuth scope mismatch
  • 7338f5a fix: show reconnect guidance for Google auth
  • 90743ca test: expand auth router coverage

@Kimgyuilli
Kimgyuilli merged commit 8ece1ed into main Apr 8, 2026
5 checks passed
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.

1 participant