File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ def find_open_port(start=8080, stop=None):
64
64
return None
65
65
66
66
67
- def run_local_server (app_flow ):
67
+ def run_local_server (app_flow , ** kwargs ):
68
68
"""Run local webserver installed app flow on some open port.
69
69
70
70
Parameters
@@ -86,4 +86,4 @@ def run_local_server(app_flow):
86
86
port = find_open_port ()
87
87
if not port :
88
88
raise exceptions .PyDataConnectionError ("Could not find open port." )
89
- return app_flow .run_local_server (host = LOCALHOST , port = port )
89
+ return app_flow .run_local_server (host = LOCALHOST , port = port , ** kwargs )
Original file line number Diff line number Diff line change 31
31
GOOGLE_AUTH_URI = "https://accounts.google.com/o/oauth2/auth"
32
32
GOOGLE_TOKEN_URI = "https://oauth2.googleapis.com/token"
33
33
34
+ AUTH_URI_KWARGS = {
35
+ # Ensure that we get a refresh token by telling Google we want to assume
36
+ # this is first time we're authorizing this app. See:
37
+ # https://github.com/googleapis/google-api-python-client/issues/213#issuecomment-205886341
38
+ "prompt" : "consent" ,
39
+ }
40
+
34
41
35
42
def _run_webapp (flow , redirect_uri = None , ** kwargs ):
36
43
@@ -352,9 +359,11 @@ def get_user_credentials(
352
359
353
360
try :
354
361
if use_local_webserver :
355
- credentials = _webserver .run_local_server (app_flow )
362
+ credentials = _webserver .run_local_server (app_flow , ** AUTH_URI_KWARGS )
356
363
else :
357
- credentials = _run_webapp (app_flow , redirect_uri = redirect_uri )
364
+ credentials = _run_webapp (
365
+ app_flow , redirect_uri = redirect_uri , ** AUTH_URI_KWARGS
366
+ )
358
367
359
368
except oauthlib .oauth2 .rfc6749 .errors .OAuth2Error as exc :
360
369
raise exceptions .PyDataCredentialsError (
You can’t perform that action at this time.
0 commit comments