Skip to content

Commit 62d92f7

Browse files
committed
Add a timeout to oauth redirect flow, so it does not hang forever
1 parent 2703518 commit 62d92f7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gcsa/_services/authentication.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import List
55

66
from googleapiclient import discovery
7-
from google_auth_oauthlib.flow import InstalledAppFlow
7+
from google_auth_oauthlib.flow import InstalledAppFlow, WSGITimeout
88
from google.auth.transport.requests import Request
99
from google.auth.credentials import Credentials
1010

@@ -107,7 +107,12 @@ def _get_credentials(
107107
else:
108108
credentials_path = os.path.join(credentials_dir, credentials_file)
109109
flow = InstalledAppFlow.from_client_secrets_file(credentials_path, scopes)
110-
credentials = flow.run_local_server(host=host, port=port, bind_addr=bind_addr)
110+
try:
111+
credentials = flow.run_local_server(
112+
host=host, port=port, bind_addr=bind_addr, timeout_seconds=120
113+
)
114+
except WSGITimeout:
115+
print('Authentication flow timed out. Please try again.')
111116

112117
if save_token:
113118
with open(token_path, 'wb') as token_file:

0 commit comments

Comments
 (0)