diff --git a/docs/reference/google.auth.app_engine.rst b/docs/reference/google.auth.app_engine.rst index 4525c089e..2142b6f50 100644 --- a/docs/reference/google.auth.app_engine.rst +++ b/docs/reference/google.auth.app_engine.rst @@ -1,7 +1,7 @@ -google.auth.app_engine module -============================= +google.auth.app\_engine module +============================== .. automodule:: google.auth.app_engine - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.compute_engine.credentials.rst b/docs/reference/google.auth.compute_engine.credentials.rst index ebe62c07c..782d95f20 100644 --- a/docs/reference/google.auth.compute_engine.credentials.rst +++ b/docs/reference/google.auth.compute_engine.credentials.rst @@ -1,7 +1,7 @@ -google.auth.compute_engine.credentials module -============================================= +google.auth.compute\_engine.credentials module +============================================== .. automodule:: google.auth.compute_engine.credentials - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.compute_engine.rst b/docs/reference/google.auth.compute_engine.rst index 2e7b830db..38785c803 100644 --- a/docs/reference/google.auth.compute_engine.rst +++ b/docs/reference/google.auth.compute_engine.rst @@ -1,10 +1,10 @@ -google.auth.compute_engine package -================================== +google.auth.compute\_engine package +=================================== .. automodule:: google.auth.compute_engine - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: Submodules ---------- @@ -12,4 +12,3 @@ Submodules .. toctree:: google.auth.compute_engine.credentials - diff --git a/docs/reference/google.auth.credentials.rst b/docs/reference/google.auth.credentials.rst index b710a8c8c..18d1d8cdf 100644 --- a/docs/reference/google.auth.credentials.rst +++ b/docs/reference/google.auth.credentials.rst @@ -2,6 +2,6 @@ google.auth.credentials module ============================== .. automodule:: google.auth.credentials - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.crypt.rst b/docs/reference/google.auth.crypt.rst index a3e2b1206..0833e7f2f 100644 --- a/docs/reference/google.auth.crypt.rst +++ b/docs/reference/google.auth.crypt.rst @@ -2,9 +2,9 @@ google.auth.crypt package ========================= .. automodule:: google.auth.crypt - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: Submodules ---------- @@ -13,4 +13,3 @@ Submodules google.auth.crypt.base google.auth.crypt.rsa - diff --git a/docs/reference/google.auth.environment_vars.rst b/docs/reference/google.auth.environment_vars.rst index fe34849dd..5996e9935 100644 --- a/docs/reference/google.auth.environment_vars.rst +++ b/docs/reference/google.auth.environment_vars.rst @@ -1,7 +1,7 @@ -google.auth.environment_vars module -=================================== +google.auth.environment\_vars module +==================================== .. automodule:: google.auth.environment_vars - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.exceptions.rst b/docs/reference/google.auth.exceptions.rst index d603eaf89..c87a7f2af 100644 --- a/docs/reference/google.auth.exceptions.rst +++ b/docs/reference/google.auth.exceptions.rst @@ -2,6 +2,6 @@ google.auth.exceptions module ============================= .. automodule:: google.auth.exceptions - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.iam.rst b/docs/reference/google.auth.iam.rst index 8a5edb450..8472ed731 100644 --- a/docs/reference/google.auth.iam.rst +++ b/docs/reference/google.auth.iam.rst @@ -2,6 +2,6 @@ google.auth.iam module ====================== .. automodule:: google.auth.iam - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.impersonated_credentials.rst b/docs/reference/google.auth.impersonated_credentials.rst index 653708ef7..f139ccf4f 100644 --- a/docs/reference/google.auth.impersonated_credentials.rst +++ b/docs/reference/google.auth.impersonated_credentials.rst @@ -2,6 +2,6 @@ google.auth.impersonated\_credentials module ============================================ .. automodule:: google.auth.impersonated_credentials - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.jwt.rst b/docs/reference/google.auth.jwt.rst index c58be5fbd..c7c2fdf62 100644 --- a/docs/reference/google.auth.jwt.rst +++ b/docs/reference/google.auth.jwt.rst @@ -2,6 +2,6 @@ google.auth.jwt module ====================== .. automodule:: google.auth.jwt - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.rst b/docs/reference/google.auth.rst index 53ab699c6..f6ea073c5 100644 --- a/docs/reference/google.auth.rst +++ b/docs/reference/google.auth.rst @@ -2,18 +2,18 @@ google.auth package =================== .. automodule:: google.auth - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: Subpackages ----------- .. toctree:: - google.auth.compute_engine - google.auth.crypt - google.auth.transport + google.auth.compute_engine + google.auth.crypt + google.auth.transport Submodules ---------- @@ -27,4 +27,3 @@ Submodules google.auth.iam google.auth.impersonated_credentials google.auth.jwt - diff --git a/docs/reference/google.auth.transport.grpc.rst b/docs/reference/google.auth.transport.grpc.rst index e16d1d853..f9f344295 100644 --- a/docs/reference/google.auth.transport.grpc.rst +++ b/docs/reference/google.auth.transport.grpc.rst @@ -2,6 +2,6 @@ google.auth.transport.grpc module ================================= .. automodule:: google.auth.transport.grpc - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.transport.requests.rst b/docs/reference/google.auth.transport.requests.rst index f31830c56..5f0c23c2d 100644 --- a/docs/reference/google.auth.transport.requests.rst +++ b/docs/reference/google.auth.transport.requests.rst @@ -2,6 +2,6 @@ google.auth.transport.requests module ===================================== .. automodule:: google.auth.transport.requests - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.auth.transport.rst b/docs/reference/google.auth.transport.rst index 1f802c3b5..48e2e0551 100644 --- a/docs/reference/google.auth.transport.rst +++ b/docs/reference/google.auth.transport.rst @@ -2,9 +2,9 @@ google.auth.transport package ============================= .. automodule:: google.auth.transport - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: Submodules ---------- @@ -14,4 +14,3 @@ Submodules google.auth.transport.grpc google.auth.transport.requests google.auth.transport.urllib3 - diff --git a/docs/reference/google.auth.transport.urllib3.rst b/docs/reference/google.auth.transport.urllib3.rst index 339c77ead..667bb0978 100644 --- a/docs/reference/google.auth.transport.urllib3.rst +++ b/docs/reference/google.auth.transport.urllib3.rst @@ -2,6 +2,6 @@ google.auth.transport.urllib3 module ==================================== .. automodule:: google.auth.transport.urllib3 - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.oauth2.credentials.rst b/docs/reference/google.oauth2.credentials.rst index ca978d148..d3bdc16de 100644 --- a/docs/reference/google.oauth2.credentials.rst +++ b/docs/reference/google.oauth2.credentials.rst @@ -2,6 +2,6 @@ google.oauth2.credentials module ================================ .. automodule:: google.oauth2.credentials - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.oauth2.id_token.rst b/docs/reference/google.oauth2.id_token.rst index db38b6085..fbe6eab8d 100644 --- a/docs/reference/google.oauth2.id_token.rst +++ b/docs/reference/google.oauth2.id_token.rst @@ -1,7 +1,7 @@ -google.oauth2.id_token module -============================= +google.oauth2.id\_token module +============================== .. automodule:: google.oauth2.id_token - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.oauth2.rst b/docs/reference/google.oauth2.rst index adb9403ef..4f1df071f 100644 --- a/docs/reference/google.oauth2.rst +++ b/docs/reference/google.oauth2.rst @@ -2,9 +2,9 @@ google.oauth2 package ===================== .. automodule:: google.oauth2 - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: Submodules ---------- @@ -14,4 +14,3 @@ Submodules google.oauth2.credentials google.oauth2.id_token google.oauth2.service_account - diff --git a/docs/reference/google.oauth2.service_account.rst b/docs/reference/google.oauth2.service_account.rst index cc4e43899..8d8fcd3f1 100644 --- a/docs/reference/google.oauth2.service_account.rst +++ b/docs/reference/google.oauth2.service_account.rst @@ -1,7 +1,7 @@ -google.oauth2.service_account module -==================================== +google.oauth2.service\_account module +===================================== .. automodule:: google.oauth2.service_account - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: diff --git a/docs/reference/google.rst b/docs/reference/google.rst index fc63d1fdb..4b1e08537 100644 --- a/docs/reference/google.rst +++ b/docs/reference/google.rst @@ -2,15 +2,14 @@ google package ============== .. automodule:: google - :members: - :inherited-members: - :show-inheritance: + :members: + :inherited-members: + :show-inheritance: Subpackages ----------- .. toctree:: - google.auth - google.oauth2 - + google.auth + google.oauth2 diff --git a/google/oauth2/_client.py b/google/oauth2/_client.py index 5121a3274..eac01b7ec 100644 --- a/google/oauth2/_client.py +++ b/google/oauth2/_client.py @@ -102,13 +102,23 @@ def _token_endpoint_request(request, token_uri, body): 'content-type': _URLENCODED_CONTENT_TYPE, } - response = request( - method='POST', url=token_uri, headers=headers, body=body) - - response_body = response.data.decode('utf-8') - - if response.status != http_client.OK: - _handle_error_response(response_body) + retry = 0 + # retry to fetch token for maximum of two times if any internal failure + # occurs. + while True: + response = request( + method='POST', url=token_uri, headers=headers, body=body) + response_body = response.data.decode('utf-8') + + if response.status == http_client.OK: + break + else: + error_desc = json.loads( + response_body).get('error_description') or '' + if error_desc == 'internal_failure' and retry < 1: + retry += 1 + continue + _handle_error_response(response_body) response_data = json.loads(response_body) diff --git a/tests/oauth2/test__client.py b/tests/oauth2/test__client.py index 5a4a56745..6fc4c3b12 100644 --- a/tests/oauth2/test__client.py +++ b/tests/oauth2/test__client.py @@ -106,6 +106,18 @@ def test__token_endpoint_request_error(): _client._token_endpoint_request(request, 'http://example.com', {}) +def test__token_endpoint_request_internal_failure_error(): + request = make_request({'error': 'internal_failure', + 'error_description': 'internal_failure'}, + status=http_client.BAD_REQUEST) + + with pytest.raises(exceptions.RefreshError): + _client._token_endpoint_request( + request, 'http://example.com', + {'error': 'internal_failure', + 'error_description': 'internal_failure'}) + + def verify_request_params(request, params): request_body = request.call_args[1]['body'] request_params = urllib.parse.parse_qs(request_body)