diff --git a/core/google/cloud/client.py b/core/google/cloud/client.py index 6a7fb1fe5554..b03b54197441 100644 --- a/core/google/cloud/client.py +++ b/core/google/cloud/client.py @@ -33,6 +33,9 @@ "for help on authentication with this library." ) +# Default timeout for auth requests. +_CREDENTIALS_REFRESH_TIMEOUT = 300 + class _ClientFactoryMixin(object): """Mixin to allow factories that create credentials. @@ -153,7 +156,8 @@ def _http(self): """ if self._http_internal is None: self._http_internal = google.auth.transport.requests.AuthorizedSession( - self._credentials + self._credentials, + refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT, ) return self._http_internal diff --git a/core/tests/unit/test_client.py b/core/tests/unit/test_client.py index 43830f902fbd..7aec69ffc701 100644 --- a/core/tests/unit/test_client.py +++ b/core/tests/unit/test_client.py @@ -122,6 +122,7 @@ def test__http_property_existing(self): self.assertIs(client._http, http) def test__http_property_new(self): + from google.cloud.client import _CREDENTIALS_REFRESH_TIMEOUT credentials = _make_credentials() client = self._make_one(credentials=credentials) self.assertIsNone(client._http_internal) @@ -133,7 +134,7 @@ def test__http_property_new(self): with authorized_session_patch as AuthorizedSession: self.assertIs(client._http, mock.sentinel.http) # Check the mock. - AuthorizedSession.assert_called_once_with(credentials) + AuthorizedSession.assert_called_once_with(credentials, refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT) # Make sure the cached value is used on subsequent access. self.assertIs(client._http_internal, mock.sentinel.http) self.assertIs(client._http, mock.sentinel.http)