#!/usr/bin/env python3 """Configurer OAuth Google par navigateur via SSH -L 8765:127.0.0.1:8765.""" from pathlib import Path from google_auth_oauthlib.flow import InstalledAppFlow from gmail_core import SCOPES,TOKEN,safe_write import sys ROOT=Path(__file__).resolve().parent path=ROOT/'credentials.json' if not path.exists():raise SystemExit('Déposer ton client OAuth Google Desktop dans '+str(path)) print('Depuis ton PC : ssh -L 8765:127.0.0.1:8765 root@IP_DU_MINIPC') print('Puis ouvrir dans ton navigateur le lien Google affiché ci-dessous.') flow=InstalledAppFlow.from_client_secrets_file(str(path),SCOPES) credentials=flow.run_local_server(host='127.0.0.1',port=8765,open_browser=False, authorization_prompt_message='Ouvre cette URL dans ton navigateur : {url}', success_message='Gmail autorisé. Tu peux fermer cette fenêtre.') safe_write(TOKEN,credentials.to_json()) print('OAuth réussi : token enregistré avec permissions restreintes dans',TOKEN)