Skip to content

Commit

Permalink
update google meet to generate the client secret file
Browse files Browse the repository at this point in the history
  • Loading branch information
jefer94 committed Sep 12, 2024
1 parent ca32e47 commit 551b205
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 10 additions & 5 deletions breathecode/services/google_meet/google_meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,31 @@ 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
if not creds or not creds.valid:
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
Expand Down
8 changes: 8 additions & 0 deletions docs/infrastructure/journal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 551b205

Please sign in to comment.