-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrefresh_auth.py
More file actions
79 lines (67 loc) · 2.9 KB
/
refresh_auth.py
File metadata and controls
79 lines (67 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""
Script to help refresh authentication tokens.
"""
import json
import os
from datetime import datetime
def check_auth_status():
"""Check current authentication status."""
auth_paths = [
"auth.json",
os.path.expanduser("~/.chatgpt-local/auth.json"),
os.path.expanduser("~/.codex/auth.json"),
]
for path in auth_paths:
try:
with open(path, "r", encoding="utf-8") as f:
auth = json.load(f)
tokens = auth.get("tokens", {})
last_refresh = auth.get("last_refresh", "unknown")
print(f"📁 Auth file: {path}")
print(f"🔑 Access token: {'✅ Present' if tokens.get('access_token') else '❌ Missing'}")
print(f"👤 Account ID: {tokens.get('account_id', 'missing')}")
print(f"🕒 Last refresh: {last_refresh}")
# Check if token might be expired (older than 1 hour)
try:
if last_refresh != "unknown":
refresh_time = datetime.fromisoformat(last_refresh.replace('Z', '+00:00'))
now = datetime.now(refresh_time.tzinfo)
age = now - refresh_time
print(f"⏰ Token age: {age}")
if age.total_seconds() > 3600: # 1 hour
print("⚠️ Token might be expired (older than 1 hour)")
else:
print("✅ Token seems fresh")
except Exception as e:
print(f"❓ Could not parse refresh time: {e}")
return True
except FileNotFoundError:
continue
except Exception as e:
print(f"❌ Error reading {path}: {e}")
continue
print("❌ No valid auth file found")
return False
def main():
"""Main function."""
print("🔍 Checking authentication status...")
print()
if not check_auth_status():
print()
print("💡 To fix authentication issues:")
print("1. Make sure you have a valid ChatGPT Plus/Pro account")
print("2. Use the original ChatMock project to re-authenticate:")
print(" - Run the original chatmock.py")
print(" - Complete the OAuth flow")
print(" - Copy the generated auth.json to this project")
print("3. Or manually update the auth.json file with fresh tokens")
return
print()
print("💡 If you're getting 403 errors:")
print("1. The access token might be expired - re-authenticate")
print("2. ChatGPT might be detecting automated requests")
print("3. Try using a different User-Agent or request headers")
print("4. Check if your ChatGPT account is still active")
if __name__ == "__main__":
main()