Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix: Ensure autogenerate_code_verifier defaults to True in from_client_config #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 google_auth_oauthlib/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def from_client_config(cls, client_config, scopes, **kwargs):

# these args cannot be passed to requests_oauthlib.OAuth2Session
code_verifier = kwargs.pop("code_verifier", None)
autogenerate_code_verifier = kwargs.pop("autogenerate_code_verifier", None)
autogenerate_code_verifier = kwargs.pop("autogenerate_code_verifier", True)

(
session,
Expand Down Expand Up @@ -237,7 +237,7 @@ def authorization_url(self, **kwargs):
specify the ``state`` when constructing the :class:`Flow`.
"""
kwargs.setdefault("access_type", "offline")
if self.autogenerate_code_verifier:
if self.code_verifier is None and self.autogenerate_code_verifier:
chars = ascii_letters + digits + "-._~"
rnd = SystemRandom()
random_verifier = [rnd.choice(chars) for _ in range(0, 128)]
Expand Down
18 changes: 12 additions & 6 deletions 18 tests/unit/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ def test_authorization_url(self, instance):

assert CLIENT_SECRETS_INFO["web"]["auth_uri"] in url
assert scope in url
assert "code_challenge=" in url
assert "code_challenge_method=S256" in url
authorization_url_spy.assert_called_with(
CLIENT_SECRETS_INFO["web"]["auth_uri"],
access_type="offline",
prompt="consent",
code_challenge=mock.ANY,
code_challenge_method="S256",
)

def test_authorization_url_code_verifier(self, instance):
Expand Down Expand Up @@ -184,10 +188,10 @@ def test_authorization_url_generated_verifier(self):
assert kwargs["code_challenge_method"] == "S256"
assert len(instance.code_verifier) == 128
assert len(kwargs["code_challenge"]) == 43
valid_verifier = r"^[A-Za-z0-9-._~]*$"
valid_challenge = r"^[A-Za-z0-9-_]*$"
assert re.match(valid_verifier, instance.code_verifier)
assert re.match(valid_challenge, kwargs["code_challenge"])
valid_verifier = r"^[A-Za-z0-9-._~]{128}$"
valid_challenge = r"^[A-Za-z0-9-_]{43}$"
assert re.fullmatch(valid_verifier, instance.code_verifier)
assert re.fullmatch(valid_challenge, kwargs["code_challenge"])

def test_fetch_token(self, instance):
instance.code_verifier = "amanaplanacanalpanama"
Expand Down Expand Up @@ -307,13 +311,15 @@ def test_run_local_server(self, webbrowser_mock, instance, mock_fetch_token, por
assert credentials.id_token == mock.sentinel.id_token
assert webbrowser_mock.get().open.called
assert instance.redirect_uri == f"http://localhost:{port}/"
valid_verifier = r"^[A-Za-z0-9-._~]{128}$"
assert re.fullmatch(valid_verifier, instance.code_verifier)

expected_auth_response = auth_redirect_url.replace("http", "https")
mock_fetch_token.assert_called_with(
CLIENT_SECRETS_INFO["web"]["token_uri"],
client_secret=CLIENT_SECRETS_INFO["web"]["client_secret"],
authorization_response=expected_auth_response,
code_verifier=None,
code_verifier=mock.ANY,
audience=None,
)

Expand Down Expand Up @@ -352,7 +358,7 @@ def test_run_local_server_audience(
CLIENT_SECRETS_INFO["web"]["token_uri"],
client_secret=CLIENT_SECRETS_INFO["web"]["client_secret"],
authorization_response=expected_auth_response,
code_verifier=None,
code_verifier=mock.ANY,
audience=self.AUDIENCE,
)

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.