#!/usr/bin/env python3
"""Re-authorize Google OAuth with Gmail + Drive + Docs scopes."""
from google_auth_oauthlib.flow import InstalledAppFlow
import json, sys

SCOPES = [
    'https://www.googleapis.com/auth/gmail.modify',
    'https://www.googleapis.com/auth/drive.readonly',
    'https://www.googleapis.com/auth/documents.readonly'
]

flow = InstalledAppFlow.from_client_secrets_file(
    '/Users/tonyclaw/.config/gmail/credentials.json',
    SCOPES
)
creds = flow.run_local_server(port=8765, open_browser=True)
token_data = {
    'token': creds.token,
    'refresh_token': creds.refresh_token,
    'token_uri': creds.token_uri,
    'client_id': creds.client_id,
    'client_secret': creds.client_secret,
    'scopes': list(creds.scopes)
}
with open('/Users/tonyclaw/.config/gmail/token.json', 'w') as f:
    json.dump(token_data, f)
print('Token saved with scopes:', creds.scopes)
