Skip to content

Commit

Permalink
samples: remove browser option from user credentials sample (googleap…
Browse files Browse the repository at this point in the history
…is#1147)

* samples: remove run_console from user credentials sample

* Update samples/snippets/user_credentials.py

Co-authored-by: Tim Swast <[email protected]>

* 🦉 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 <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and abdelmegahedgoogle committed Apr 17, 2023
1 parent a7b8021 commit c5eee67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions samples/snippets/user_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/user_credentials_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c5eee67

Please sign in to comment.