Skip to content

Commit 666863a

Browse files
fix: add redirect_uri_trailing slash param to run_local_server (#111)
* fix: add redirect_uri_trailing slash param to run_local_server * chore: register webtest marker
1 parent 59e4c58 commit 666863a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

google_auth_oauthlib/flow.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def run_local_server(
422422
authorization_prompt_message=_DEFAULT_AUTH_PROMPT_MESSAGE,
423423
success_message=_DEFAULT_WEB_SUCCESS_MESSAGE,
424424
open_browser=True,
425+
redirect_uri_trailing_slash=True,
425426
**kwargs
426427
):
427428
"""Run the flow using the server strategy.
@@ -444,6 +445,8 @@ def run_local_server(
444445
the authorization flow is complete.
445446
open_browser (bool): Whether or not to open the authorization URL
446447
in the user's browser.
448+
redirect_uri_trailing_slash (bool): whether or not to add trailing
449+
slash when constructing the redirect_uri. Default value is True.
447450
kwargs: Additional keyword arguments passed through to
448451
:meth:`authorization_url`.
449452
@@ -458,7 +461,10 @@ def run_local_server(
458461
host, port, wsgi_app, handler_class=_WSGIRequestHandler
459462
)
460463

461-
self.redirect_uri = "http://{}:{}/".format(host, local_server.server_port)
464+
redirect_uri_format = (
465+
"http://{}:{}/" if redirect_uri_trailing_slash else "http://{}:{}"
466+
)
467+
self.redirect_uri = redirect_uri_format.format(host, local_server.server_port)
462468
auth_url, _ = self.authorization_url(**kwargs)
463469

464470
if open_browser:

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
markers =
3+
webtest: mark a test as a webtest.

tests/unit/test_flow.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def test_run_local_server(self, webbrowser_mock, instance, mock_fetch_token, por
321321
assert credentials._refresh_token == mock.sentinel.refresh_token
322322
assert credentials.id_token == mock.sentinel.id_token
323323
assert webbrowser_mock.open.called
324+
assert instance.redirect_uri == f"http://localhost:{port}/"
324325

325326
expected_auth_response = auth_redirect_url.replace("http", "https")
326327
mock_fetch_token.assert_called_with(
@@ -341,7 +342,13 @@ def test_run_local_server_code_verifier(
341342
instance.code_verifier = "amanaplanacanalpanama"
342343

343344
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
344-
future = pool.submit(partial(instance.run_local_server, port=port))
345+
future = pool.submit(
346+
partial(
347+
instance.run_local_server,
348+
port=port,
349+
redirect_uri_trailing_slash=False,
350+
)
351+
)
345352

346353
while not future.done():
347354
try:
@@ -355,6 +362,7 @@ def test_run_local_server_code_verifier(
355362
assert credentials._refresh_token == mock.sentinel.refresh_token
356363
assert credentials.id_token == mock.sentinel.id_token
357364
assert webbrowser_mock.open.called
365+
assert instance.redirect_uri == f"http://localhost:{port}"
358366

359367
expected_auth_response = auth_redirect_url.replace("http", "https")
360368
mock_fetch_token.assert_called_with(

0 commit comments

Comments
 (0)