From e13057e6a73d96aec7fc06c9f7989fceb40b1bfb Mon Sep 17 00:00:00 2001 From: happybell80 Date: Wed, 10 Sep 2025 00:28:17 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20Gmail=20token=20=EB=B6=88=EC=9D=BC?= =?UTF-8?q?=EC=B9=98=20=EB=AC=B8=EC=84=9C=20=EB=82=A0=EC=A7=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=ED=98=84=ED=99=A9=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 파일명 250109 → 250909로 수정 - DB 현황 추가 (23:36 갱신 기준) - 긴급 DB 동기화 SQL 우선순위 변경 --- ...ppybell80_gmail_refresh_token_불일치.md | 49 ----------------- ...ppybell80_gmail_refresh_token_불일치.md | 52 +++++++++++++++++++ 2 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md create mode 100644 troubleshooting/250909_happybell80_gmail_refresh_token_불일치.md diff --git a/troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md b/troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md deleted file mode 100644 index a48bb9a..0000000 --- a/troubleshooting/250109_happybell80_gmail_refresh_token_불일치.md +++ /dev/null @@ -1,49 +0,0 @@ -# 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 diff --git a/troubleshooting/250909_happybell80_gmail_refresh_token_불일치.md b/troubleshooting/250909_happybell80_gmail_refresh_token_불일치.md new file mode 100644 index 0000000..5d8ebe1 --- /dev/null +++ b/troubleshooting/250909_happybell80_gmail_refresh_token_불일치.md @@ -0,0 +1,52 @@ +# Gmail refresh_token 컬럼/JSONB 불일치 문제 + +**작성일**: 2025-09-09 +**작성자**: happybell80 & Claude +**영향 서비스**: 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 (정상 작동) +``` + +## DB 현황 (23:36 갱신) +김종태: token_data와 컬럼 불일치 (다른 토큰) +Heejae: 양쪽 일치 (동일 토큰) +HanYong: token_data 비어있음 (8/30 이후) + +## 코드 분석 +### skill-email (문제) +- 63번: refresh_token 컬럼 조회 → 무효 토큰 사용 +- 166번: 컬럼만 업데이트 → JSONB 동기화 안됨 + +### auth-server (정상) +- token_data JSONB 사용 중 + +## 해결 방안 +```sql +-- 1. 긴급: DB 동기화 (무효 토큰 문제 즉시 해결) +UPDATE gmail_tokens +SET refresh_token = token_data->>'refresh_token', + access_token = token_data->>'access_token' +WHERE token_data IS NOT NULL; + +-- 2. 근본: skill-email 코드 JSONB 전환 +-- 63번: token_data->>'refresh_token' as refresh_token +-- 166번: token_data = jsonb_set(...) 사용 +``` + +## 교훈 +- 레거시 컬럼과 JSONB 병행 사용 시 동기화 필수 +- 코드 마이그레이션 시 모든 서비스 일괄 수정 +- 토큰 갱신 실패 시 저장 위치 불일치 확인 \ No newline at end of file