Skip to content

Commit 6fb5434

Browse files
CodingFanStevebusunkim96
authored andcommitted
fix: in token endpoint request, do not decode the response data if it 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.
1 parent c245182 commit 6fb5434

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/google-auth/google/oauth2/_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ def _token_endpoint_request(request, token_uri, body):
103103
# occurs.
104104
while True:
105105
response = request(method="POST", url=token_uri, headers=headers, body=body)
106-
response_body = response.data.decode("utf-8")
106+
response_body = (
107+
response.data.decode("utf-8")
108+
if hasattr(response.data, "decode")
109+
else response.data
110+
)
107111
response_data = json.loads(response_body)
108112

109113
if response.status == http_client.OK:

0 commit comments

Comments
 (0)