Skip to content

Commit 3dd85eb

Browse files
authored
enable no printing to stdout during auth flow (#203)
Currently, `run_console` and `run_local_server` unconditionally print a newline to `stdout` even when `authorization_prompt_message` is empty. This proposed change checks whether printing is actually desired, and if not, prints nothing.
1 parent a9d32cd commit 3dd85eb

File tree

1 file changed

+10
-6
lines changed
  • packages/google-auth-oauthlib/google_auth_oauthlib

1 file changed

+10
-6
lines changed

packages/google-auth-oauthlib/google_auth_oauthlib/flow.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ def run_console(
408408
code into the application. The code is then exchanged for a token.
409409
410410
Args:
411-
authorization_prompt_message (str): The message to display to tell
412-
the user to navigate to the authorization URL.
411+
authorization_prompt_message (str | None): The message to display to tell
412+
the user to navigate to the authorization URL. If None or empty,
413+
don't display anything.
413414
authorization_code_message (str): The message to display when
414415
prompting the user for the authorization code.
415416
kwargs: Additional keyword arguments passed through to
@@ -432,7 +433,8 @@ def run_console(
432433

433434
auth_url, _ = self.authorization_url(**kwargs)
434435

435-
print(authorization_prompt_message.format(url=auth_url))
436+
if authorization_prompt_message:
437+
print(authorization_prompt_message.format(url=auth_url))
436438

437439
code = input(authorization_code_message)
438440

@@ -471,8 +473,9 @@ def run_local_server(
471473
which means that the redirect server will listen
472474
on the ip address specified in the host parameter.
473475
port (int): The port for the local redirect server.
474-
authorization_prompt_message (str): The message to display to tell
475-
the user to navigate to the authorization URL.
476+
authorization_prompt_message (str | None): The message to display to tell
477+
the user to navigate to the authorization URL. If None or empty,
478+
don't display anything.
476479
success_message (str): The message to display in the web browser
477480
the authorization flow is complete.
478481
open_browser (bool): Whether or not to open the authorization URL
@@ -506,7 +509,8 @@ def run_local_server(
506509
if open_browser:
507510
webbrowser.open(auth_url, new=1, autoraise=True)
508511

509-
print(authorization_prompt_message.format(url=auth_url))
512+
if authorization_prompt_message:
513+
print(authorization_prompt_message.format(url=auth_url))
510514

511515
local_server.timeout = timeout_seconds
512516
local_server.handle_request()

0 commit comments

Comments
 (0)