Skip to content

Commit

Permalink
Handle case where there is no system browser
Browse files Browse the repository at this point in the history
  • Loading branch information
mafrosis committed Jul 8, 2024
1 parent 62d92f7 commit 952d2d0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gcsa/_services/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path
import glob
from typing import List
import webbrowser

from googleapiclient import discovery
from google_auth_oauthlib.flow import InstalledAppFlow, WSGITimeout
Expand Down Expand Up @@ -93,7 +94,8 @@ def _get_credentials(
save_token: bool,
host: str,
port: int,
bind_addr: str
bind_addr: str,
open_browser: bool = True
) -> Credentials:
credentials = None

Expand All @@ -109,7 +111,14 @@ def _get_credentials(
flow = InstalledAppFlow.from_client_secrets_file(credentials_path, scopes)
try:
credentials = flow.run_local_server(
host=host, port=port, bind_addr=bind_addr, timeout_seconds=120
host=host, port=port, bind_addr=bind_addr, timeout_seconds=120,
open_browser=open_browser
)
except webbrowser.Error:
# System has no default browser configured, retry without opening browser
return AuthenticatedService._get_credentials(
token_path, credentials_dir, credentials_file, scopes, save_token, host, port,
bind_addr, open_browser=False
)
except WSGITimeout:
print('Authentication flow timed out. Please try again.')
Expand Down

0 comments on commit 952d2d0

Please sign in to comment.