-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreauth_google.py
More file actions
executable file
·31 lines (25 loc) · 1.11 KB
/
reauth_google.py
File metadata and controls
executable file
·31 lines (25 loc) · 1.11 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
#!/usr/bin/env python3
"""Re-authenticate Google OAuth with expanded scopes for CODEC"""
import os
CREDS_PATH = os.path.expanduser("~/.codec/google_credentials.json")
TOKEN_PATH = os.path.expanduser("~/.codec/google_token.json")
SCOPES = [
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/documents",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/presentations",
"https://www.googleapis.com/auth/tasks"
]
# Delete old token to force re-auth
if os.path.exists(TOKEN_PATH):
os.rename(TOKEN_PATH, TOKEN_PATH + ".backup")
print(f"Backed up old token to {TOKEN_PATH}.backup")
from google_auth_oauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.from_client_secrets_file(CREDS_PATH, SCOPES)
creds = flow.run_local_server(port=0)
with open(TOKEN_PATH, "w") as f:
f.write(creds.to_json())
print(f"\n\u2705 New token saved with {len(SCOPES)} scopes!")
print("Skills now available: Gmail, Calendar, Drive, Docs, Sheets, Slides, Tasks")