From 666863aeabb8d6b3608ea95edce09fe69a5f2679 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Mon, 29 Mar 2021 12:41:29 -0700 Subject: [PATCH 1/2] 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 --- google_auth_oauthlib/flow.py | 8 +++++++- pytest.ini | 3 +++ tests/unit/test_flow.py | 10 +++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 pytest.ini diff --git a/google_auth_oauthlib/flow.py b/google_auth_oauthlib/flow.py index 4e13ac4..d20ed9e 100644 --- a/google_auth_oauthlib/flow.py +++ b/google_auth_oauthlib/flow.py @@ -422,6 +422,7 @@ def run_local_server( authorization_prompt_message=_DEFAULT_AUTH_PROMPT_MESSAGE, success_message=_DEFAULT_WEB_SUCCESS_MESSAGE, open_browser=True, + redirect_uri_trailing_slash=True, **kwargs ): """Run the flow using the server strategy. @@ -444,6 +445,8 @@ def run_local_server( the authorization flow is complete. open_browser (bool): Whether or not to open the authorization URL in the user's browser. + redirect_uri_trailing_slash (bool): whether or not to add trailing + slash when constructing the redirect_uri. Default value is True. kwargs: Additional keyword arguments passed through to :meth:`authorization_url`. @@ -458,7 +461,10 @@ def run_local_server( host, port, wsgi_app, handler_class=_WSGIRequestHandler ) - self.redirect_uri = "http://{}:{}/".format(host, local_server.server_port) + redirect_uri_format = ( + "http://{}:{}/" if redirect_uri_trailing_slash else "http://{}:{}" + ) + self.redirect_uri = redirect_uri_format.format(host, local_server.server_port) auth_url, _ = self.authorization_url(**kwargs) if open_browser: diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..85b71c5 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + webtest: mark a test as a webtest. \ No newline at end of file diff --git a/tests/unit/test_flow.py b/tests/unit/test_flow.py index ea9afd9..3850b25 100644 --- a/tests/unit/test_flow.py +++ b/tests/unit/test_flow.py @@ -321,6 +321,7 @@ def test_run_local_server(self, webbrowser_mock, instance, mock_fetch_token, por assert credentials._refresh_token == mock.sentinel.refresh_token assert credentials.id_token == mock.sentinel.id_token assert webbrowser_mock.open.called + assert instance.redirect_uri == f"http://localhost:{port}/" expected_auth_response = auth_redirect_url.replace("http", "https") mock_fetch_token.assert_called_with( @@ -341,7 +342,13 @@ def test_run_local_server_code_verifier( instance.code_verifier = "amanaplanacanalpanama" with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool: - future = pool.submit(partial(instance.run_local_server, port=port)) + future = pool.submit( + partial( + instance.run_local_server, + port=port, + redirect_uri_trailing_slash=False, + ) + ) while not future.done(): try: @@ -355,6 +362,7 @@ def test_run_local_server_code_verifier( assert credentials._refresh_token == mock.sentinel.refresh_token assert credentials.id_token == mock.sentinel.id_token assert webbrowser_mock.open.called + assert instance.redirect_uri == f"http://localhost:{port}" expected_auth_response = auth_redirect_url.replace("http", "https") mock_fetch_token.assert_called_with( From 708be131030f375b92ab1abdd042ffd1dab12278 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 29 Mar 2021 12:47:56 -0700 Subject: [PATCH 2/2] chore: release 0.4.4 (#112) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5e9976..17a8bb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ [1]: https://pypi.org/project/google-auth-oauthlib/#history +### [0.4.4](https://www.github.com/googleapis/google-auth-library-python-oauthlib/compare/v0.4.3...v0.4.4) (2021-03-29) + + +### Bug Fixes + +* add redirect_uri_trailing slash param to run_local_server ([#111](https://www.github.com/googleapis/google-auth-library-python-oauthlib/issues/111)) ([666863a](https://www.github.com/googleapis/google-auth-library-python-oauthlib/commit/666863aeabb8d6b3608ea95edce09fe69a5f2679)) + ### [0.4.3](https://www.github.com/googleapis/google-auth-library-python-oauthlib/compare/v0.4.2...v0.4.3) (2021-02-12) diff --git a/setup.py b/setup.py index f5fbe68..f717e02 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ long_description = fh.read() -version = "0.4.3" +version = "0.4.4" setup( name="google-auth-oauthlib",