Skip to content

Commit 73d419f

Browse files
authored
fix: ensure we always get a refresh token after the auth prompt (#72)
* fix: ensure we always get a refresh token after the auth prompt * fix lint
1 parent a09e6f6 commit 73d419f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pydata_google_auth/_webserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def find_open_port(start=8080, stop=None):
6464
return None
6565

6666

67-
def run_local_server(app_flow):
67+
def run_local_server(app_flow, **kwargs):
6868
"""Run local webserver installed app flow on some open port.
6969
7070
Parameters
@@ -86,4 +86,4 @@ def run_local_server(app_flow):
8686
port = find_open_port()
8787
if not port:
8888
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)

pydata_google_auth/auth.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
GOOGLE_AUTH_URI = "https://accounts.google.com/o/oauth2/auth"
3232
GOOGLE_TOKEN_URI = "https://oauth2.googleapis.com/token"
3333

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+
3441

3542
def _run_webapp(flow, redirect_uri=None, **kwargs):
3643

@@ -352,9 +359,11 @@ def get_user_credentials(
352359

353360
try:
354361
if use_local_webserver:
355-
credentials = _webserver.run_local_server(app_flow)
362+
credentials = _webserver.run_local_server(app_flow, **AUTH_URI_KWARGS)
356363
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+
)
358367

359368
except oauthlib.oauth2.rfc6749.errors.OAuth2Error as exc:
360369
raise exceptions.PyDataCredentialsError(

0 commit comments

Comments
 (0)