Skip to content

Commit

Permalink
fix: in token endpoint request, do not decode the response data if it…
Browse files Browse the repository at this point in the history
… is not encoded (#393)

* fix: in token endpoint request, do not decode the response data if it is not encoded

The interface of the underlying transport
'google.auth.transport.Request' that makes the token
request does not guarantee the response is encoded. In Python 3, the
non-encoded strings do not have 'decode' attribute. Blindly decoding all
the response could have the token refresh throw here.
  • Loading branch information
CodingFanSteve authored and busunkim96 committed Dec 2, 2019
1 parent 0c33e9c commit 3b5d3e2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion google/oauth2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ def _token_endpoint_request(request, token_uri, body):
# occurs.
while True:
response = request(method="POST", url=token_uri, headers=headers, body=body)
response_body = response.data.decode("utf-8")
response_body = (
response.data.decode("utf-8")
if hasattr(response.data, "decode")
else response.data
)
response_data = json.loads(response_body)

if response.status == http_client.OK:
Expand Down

0 comments on commit 3b5d3e2

Please sign in to comment.