# Gmail Calendar Scope 및 Timezone 트러블슈팅 **작성일**: 2025-11-14 ~ 2025-11-16 **작성자**: Claude --- ## 1. Calendar Scope 추가 (2025-11-14) ### 문제 - skill-calendar가 Google Calendar API 호출 시 `invalid_grant` 에러 - 원인: Gmail Passport scope에 Calendar API 권한 없음 ### 해결 **auth-server scope 수정** (`app/providers/gmail_passport.py`): ```python GMAIL_API_SCOPES = [ "https://www.googleapis.com/auth/gmail.send", "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.modify", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/calendar", # 추가 "https://www.googleapis.com/auth/calendar.events" # 추가 ] ``` **재배포 및 재인증**: ```bash cd /home/admin/auth-server git add app/providers/gmail_passport.py git commit -m "feat: Calendar scope 추가" git push origin main ``` 웹에서 Gmail 재인증 → Google 권한 동의 → Calendar scope 확인 → 허용 --- ## 2. Calendar CRUD Timezone 이슈 (2025-11-16) ### 문제 - **CREATE**: 성공 - **READ**: 방금 등록한 일정 조회 실패 - **DELETE**: 성공하지만 잘못된 날짜 표시 ### 원인 naive datetime (timezone 없음) 사용: ```python # 문제 start_iso = f"{date}T{start_hour}:{start_min}:00" # "2025-11-17T15:00:00" # Google Calendar API는 timezone 없으면 해석 불확실 # rb8001 → skill-calendar 전송 시 timezone 불일치 ``` ### 해결 **rb8001/app/router/calendar_handler.py 수정**: **parse_time_range()** (Line 397): ```python from datetime import datetime from zoneinfo import ZoneInfo year, month, day = map(int, date.split('-')) tz = ZoneInfo("Asia/Seoul") start_dt = datetime(year, month, day, int(start_hour), int(start_min), 0, tzinfo=tz) end_dt = datetime(year, month, day, int(end_hour), int(end_min), 0, tzinfo=tz) return start_dt.isoformat(), end_dt.isoformat() # "2025-11-17T15:00:00+09:00" ``` **handle_calendar_query()** (Line 228): ```python today = datetime.now(ZoneInfo("Asia/Seoul")) target_date = datetime(year, month, day, tzinfo=ZoneInfo("Asia/Seoul")) ``` ### 테스트 결과 **Before (67%)**: - ✅ CREATE - ❌ READ (조회 실패) - ✅ DELETE **After (100%)**: - ✅ CREATE - ✅ READ (조회 성공) - ✅ DELETE (정확한 날짜 표시) --- ## 3. 교훈 ### Datetime 규칙 - **절대 금지**: naive datetime (timezone 없음) - **필수**: `datetime.now(ZoneInfo("Asia/Seoul"))` - **전송**: ISO 8601 with timezone (`2025-11-17T15:00:00+09:00`) ### Microservice 간 통신 - 모든 datetime은 timezone offset 포함 - UTC 통일 또는 명시적 timezone 사용 - 컨테이너 시스템 timezone 확인: `docker exec [컨테이너] date` --- ## 4. 관련 커밋 - `4cd0990`: fix: Add timezone awareness to calendar operations - `fd7ec1c`: Revert README.md documentation changes