| |
| """ |
| Extract Gemini CLI OAuth credentials from Windows |
| """ |
|
|
| import os |
| import json |
| import sys |
| from pathlib import Path |
|
|
| def extract(): |
| |
| if sys.platform == 'win32': |
| gemini_dir = Path(os.environ.get('USERPROFILE', '')) / '.gemini' |
| else: |
| gemini_dir = Path.home() / '.gemini' |
| |
| oauth_file = gemini_dir / 'oauth_creds.json' |
| |
| print("=" * 60) |
| print("Gemini CLI OAuth Credential Extractor") |
| print("=" * 60) |
| |
| if not oauth_file.exists(): |
| print(f"\n[ERROR] OAuth file not found: {oauth_file}") |
| print("\nPlease ensure you have logged into Gemini CLI at least once.") |
| print("Run: gemini") |
| print("And select 'Login with Google'") |
| return None |
| |
| try: |
| with open(oauth_file, 'r') as f: |
| creds = json.load(f) |
| |
| |
| if 'refresh_token' not in creds: |
| print("[ERROR] No refresh_token found") |
| return None |
| |
| print(f"\n[OK] Found OAuth credentials") |
| print(f" Access Token: {creds.get('access_token', '')[:30]}...") |
| print(f" Refresh Token: {creds.get('refresh_token', '')[:20]}...") |
| |
| if 'expiry_date' in creds: |
| from datetime import datetime |
| expiry = datetime.fromtimestamp(creds['expiry_date'] / 1000) |
| print(f" Expires: {expiry}") |
| |
| print("\n" + "=" * 60) |
| print("FOR HUGGINGFACE SECRETS:") |
| print("=" * 60) |
| print("\nSecret Name: GEMINI_OAUTH_CREDS") |
| print("\nSecret Value:") |
| print("-" * 60) |
| print(json.dumps(creds)) |
| print("-" * 60) |
| |
| return creds |
| |
| except Exception as e: |
| print(f"[ERROR] {e}") |
| return None |
|
|
| if __name__ == '__main__': |
| extract() |
|
|