From 9336ed658d8455a817d291786056a517d64b1b16 Mon Sep 17 00:00:00 2001 From: happybell80 Date: Tue, 9 Sep 2025 23:55:18 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20Gmail=20refresh=5Ftoken=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC/JSONB=20=EB=B6=88=EC=9D=BC=EC=B9=98=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=8A=B8=EB=9F=AC=EB=B8=94=EC=8A=88=ED=8C=85=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ppybell80_gmail_refresh_token_불일치.md | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md diff --git a/troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md b/troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md new file mode 100644 index 0000000..a48bb9a --- /dev/null +++ b/troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md @@ -0,0 +1,49 @@ +# Gmail refresh_token 컬럼/JSONB 불일치 문제 + +**작성일**: 2025-01-09 +**작성자**: happybell80 +**영향 서비스**: skill-email, auth-server + +## 문제 상황 +Gmail 토큰 테이블에서 refresh_token이 두 곳에 저장: +- `refresh_token` 컬럼 (오래된 무효 토큰) +- `token_data` JSONB (실제 유효 토큰) + +## 발견 과정 +```python +# refresh_token 컬럼 토큰 테스트 +토큰: 1//0g53CfEfA9Pw6... +결과: 400 invalid_grant (만료/무효) + +# token_data JSONB 토큰 테스트 +토큰: 1//0glv3xMaPHgvW... +결과: 200 OK (정상 작동) +``` + +## 코드 분석 +### skill-email/services/db_credentials_provider.py +- 63번줄: `refresh_token,` (컬럼 직접 조회) +- 166번줄: `refresh_token = %s,` (컬럼 업데이트) +- 문제: 오래된 컬럼 사용으로 토큰 갱신 실패 가능 + +### auth-server/app/api/gmail_refresh.py +- 74번줄: `token_data.get('refresh_token')` (JSONB 사용) +- 정상: 이미 JSONB만 사용 중 + +## 해결 방안 +```sql +-- 1. skill-email 코드 수정 (4줄) +-- 63번: refresh_token → token_data->>'refresh_token' as refresh_token +-- 166번: refresh_token = %s, 삭제 +-- 173번: creds.refresh_token, 삭제 + +-- 2. DB 데이터 동기화 (선택) +UPDATE gmail_tokens +SET refresh_token = token_data->>'refresh_token' +WHERE slack_user_id = 'U0925SXQFDK'; +``` + +## 교훈 +- 레거시 컬럼과 JSONB 병행 사용 시 동기화 필수 +- 코드 마이그레이션 시 모든 서비스 일괄 수정 +- 토큰 갱신 실패 시 저장 위치 불일치 확인 \ No newline at end of file