Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: always pass body of type bytes to google.auth.transport.Request #421

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

Merged
merged 3 commits into from
Jan 10, 2020
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
4 changes: 3 additions & 1 deletion google/auth/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def _make_signing_request(self, message):
method = "POST"
url = _SIGN_BLOB_URI.format(self._service_account_email)
headers = {}
body = json.dumps({"bytesToSign": base64.b64encode(message).decode("utf-8")})
body = json.dumps(
{"bytesToSign": base64.b64encode(message).decode("utf-8")}
).encode("utf-8")

self._credentials.before_request(self._request, method, url, headers)
response = self._request(url=url, method=method, body=body, headers=headers)
Expand Down
2 changes: 1 addition & 1 deletion google/auth/impersonated_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _make_iam_token_request(request, principal, headers, body):
"""
iam_endpoint = _IAM_ENDPOINT.format(principal)

body = json.dumps(body)
body = json.dumps(body).encode("utf-8")

response = request(url=iam_endpoint, method="POST", headers=headers, body=body)

Expand Down
2 changes: 1 addition & 1 deletion google/oauth2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _token_endpoint_request(request, token_uri, body):
google.auth.exceptions.RefreshError: If the token endpoint returned
an error.
"""
body = urllib.parse.urlencode(body)
body = urllib.parse.urlencode(body).encode("utf-8")
headers = {"content-type": _URLENCODED_CONTENT_TYPE}

retry = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/oauth2/test__client.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test__token_endpoint_request():
method="POST",
url="http://example.com",
headers={"content-type": "application/x-www-form-urlencoded"},
body="test=params",
body="test=params".encode("utf-8"),
)

# Check result
Expand Down Expand Up @@ -131,7 +131,7 @@ def test__token_endpoint_request_internal_failure_error():


def verify_request_params(request, params):
request_body = request.call_args[1]["body"]
request_body = request.call_args[1]["body"].decode("utf-8")
request_params = urllib.parse.parse_qs(request_body)

for key, value in six.iteritems(params):
Expand Down