From c5eee673d2398acf29b4346c160ed2467b112237 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Wed, 2 Mar 2022 10:01:40 -0700 Subject: [PATCH] samples: remove browser option from user credentials sample (#1147) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * samples: remove run_console from user credentials sample * Update samples/snippets/user_credentials.py Co-authored-by: Tim Swast * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Tim Swast Co-authored-by: Owl Bot --- samples/snippets/user_credentials.py | 22 +++++++++------------- samples/snippets/user_credentials_test.py | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/samples/snippets/user_credentials.py b/samples/snippets/user_credentials.py index 6089d9fd9..e8dccf143 100644 --- a/samples/snippets/user_credentials.py +++ b/samples/snippets/user_credentials.py @@ -23,26 +23,22 @@ import argparse -def main(project, launch_browser=True): +def main(project): # [START bigquery_auth_user_flow] from google_auth_oauthlib import flow - # TODO: Uncomment the line below to set the `launch_browser` variable. - # launch_browser = True - # - # The `launch_browser` boolean variable indicates if a local server is used - # as the callback URL in the auth flow. A value of `True` is recommended, - # but a local server does not work if accessing the application remotely, - # such as over SSH or from a remote Jupyter notebook. - + # A local server is used as the callback URL in the auth flow. appflow = flow.InstalledAppFlow.from_client_secrets_file( "client_secrets.json", scopes=["https://www.googleapis.com/auth/bigquery"] ) - if launch_browser: - appflow.run_local_server() - else: - appflow.run_console() + # This launches a local server to be used as the callback URL in the desktop + # app auth flow. If you are accessing the application remotely, such as over + # SSH or a remote Jupyter notebook, this flow will not work. Use the + # `gcloud auth application-default login --no-browser` command or workload + # identity federation to get authentication tokens, instead. + # + appflow.run_local_server() credentials = appflow.credentials # [END bigquery_auth_user_flow] diff --git a/samples/snippets/user_credentials_test.py b/samples/snippets/user_credentials_test.py index 829502d25..66c1bddb7 100644 --- a/samples/snippets/user_credentials_test.py +++ b/samples/snippets/user_credentials_test.py @@ -35,7 +35,7 @@ def mock_flow(): def test_auth_query_console(mock_flow, capsys): - main(PROJECT, launch_browser=False) + main(PROJECT) out, _ = capsys.readouterr() # Fun fact: William P. Wood was the 1st director of the US Secret Service. assert "William" in out