diff --git a/breathecode/services/google_meet/google_meet.py b/breathecode/services/google_meet/google_meet.py index 5e9ca0b67..75c717898 100644 --- a/breathecode/services/google_meet/google_meet.py +++ b/breathecode/services/google_meet/google_meet.py @@ -84,14 +84,15 @@ class ListParticipantsRequest(TypedDict): # Scopes for Google Calendar API (used for creating Google Meet links) SCOPES = ["https://www.googleapis.com/auth/calendar"] -CREDENTIAL_FILE_NAME = "google_cloud_oauth_token.pickle" +TOKEN_FILE_NAME = "google_cloud_oauth_token.pickle" +GOOGLE_CLIENT_SECRET = "client_secret.json" def get_credentials(): creds = None # Check if google_meet_oauth_token.pickle exists (to reuse the token) - if os.path.exists(CREDENTIAL_FILE_NAME): - with open(CREDENTIAL_FILE_NAME, "rb") as token: + if os.path.exists(TOKEN_FILE_NAME): + with open(TOKEN_FILE_NAME, "rb") as token: creds = pickle.load(token) # If there are no valid credentials available, prompt the user to log in @@ -99,11 +100,15 @@ def get_credentials(): if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: - flow = InstalledAppFlow.from_client_secrets_file("client_secret.json", SCOPES) + if not os.path.exists(GOOGLE_CLIENT_SECRET): + with open(GOOGLE_CLIENT_SECRET, "w") as f: + f.write(os.getenv("GOOGLE_CLIENT_SECRET", "")) + + flow = InstalledAppFlow.from_client_secrets_file(GOOGLE_CLIENT_SECRET, SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open(CREDENTIAL_FILE_NAME, "wb") as token: + with open(TOKEN_FILE_NAME, "wb") as token: pickle.dump(creds, token) return creds diff --git a/docs/infrastructure/journal.md b/docs/infrastructure/journal.md index d18d6abda..aeb165233 100644 --- a/docs/infrastructure/journal.md +++ b/docs/infrastructure/journal.md @@ -67,3 +67,11 @@ Reasons for the change: - `[all]` `GOOGLE_SECRET` setted. - `[dev]` `GOOGLE_CLIENT_ID` setted. - `[all]` `GOOGLE_REDIRECT_URL` setted. + +## 11/09/2024 + +- `[all]` `GOOGLE_CLIENT_SECRET` setted. + +Why: + +- To enable the oauth flow for the Google Meet API.