From 87c6b03d384c0940a1847aaa12ff6e35f2db19f2 Mon Sep 17 00:00:00 2001 From: CodingFanSteve Date: Tue, 26 Nov 2019 13:50:06 -0800 Subject: [PATCH 1/2] 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. --- google/oauth2/_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google/oauth2/_client.py b/google/oauth2/_client.py index f92b0970a..45f657e97 100644 --- a/google/oauth2/_client.py +++ b/google/oauth2/_client.py @@ -103,7 +103,8 @@ 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: From c317fc3de0626c461c25815bf38fed72c8f8a82d Mon Sep 17 00:00:00 2001 From: CodingFanSteve Date: Wed, 27 Nov 2019 13:49:48 -0800 Subject: [PATCH 2/2] Ran 'black google tests noxfile.py setup.py docs/conf.py' to format the code --- google/oauth2/_client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/google/oauth2/_client.py b/google/oauth2/_client.py index 45f657e97..4cf7a7fe9 100644 --- a/google/oauth2/_client.py +++ b/google/oauth2/_client.py @@ -103,8 +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') if hasattr( - response.data, 'decode') else response.data + 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: