Skip to content
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

fix: don't retry if error or error_description is not string #1241

Merged
merged 3 commits into from
Mar 1, 2023
Merged
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
5 changes: 5 additions & 0 deletions google/oauth2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def _can_retry(status_code, response_data):
error_desc = response_data.get("error_description") or ""
error_code = response_data.get("error") or ""

if not isinstance(error_code, six.string_types) or not isinstance(
error_desc, six.string_types
):
return False

# Per Oauth 2.0 RFC https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1.2.1
# This is needed because a redirect will not return a 500 status code.
retryable_error_descriptions = {
Expand Down
2 changes: 1 addition & 1 deletion samples/cloud-client/snippets/verify_google_idtoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def verify_google_idtoken(idtoken: str, audience="iap.googleapis.com",
request = google.auth.transport.requests.Request()
# Set the parameters and verify the token.
# Setting "certs_url" is optional. When verifying a Google ID token, this is set by default.
result = id_token.verify_token(idtoken, request, audience)
result = id_token.verify_token(idtoken, request, audience, clock_skew_in_seconds=10)

# Verify that the token contains subject and email claims.
# Get the User id.
Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
9 changes: 8 additions & 1 deletion tests/oauth2/test__client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ def test__can_retry_message(response_data):
assert _client._can_retry(http_client.OK, response_data)


@pytest.mark.parametrize("response_data", [{"error": "invalid_scope"}])
@pytest.mark.parametrize(
"response_data",
[
{"error": "invalid_scope"},
{"error": {"foo": "bar"}},
{"error_description": {"foo", "bar"}},
],
)
def test__can_retry_no_retry_message(response_data):
assert not _client._can_retry(http_client.OK, response_data)

Expand Down