diff --git a/src/kognic/auth/base/auth_client.py b/src/kognic/auth/base/auth_client.py index 965de08..59801ae 100644 --- a/src/kognic/auth/base/auth_client.py +++ b/src/kognic/auth/base/auth_client.py @@ -31,3 +31,9 @@ def expires_at(self): @property def token(self): raise NotImplementedError + + @staticmethod + def check_rate_limit(response): + if response.status_code == 429: + log.error("Client authentication rate limit exceeded! Please slow down.") + return response diff --git a/src/kognic/auth/httpx/async_client.py b/src/kognic/auth/httpx/async_client.py index 945a61e..98cba71 100644 --- a/src/kognic/auth/httpx/async_client.py +++ b/src/kognic/auth/httpx/async_client.py @@ -57,6 +57,8 @@ def __init__( grant_type="client_credentials", **kwargs, ) + self._oauth_client.register_compliance_hook("access_token_response", AuthClient.check_rate_limit) + self._oauth_client.register_compliance_hook("refresh_token_response", AuthClient.check_rate_limit) self._lock = Lock() diff --git a/src/kognic/auth/requests/auth_session.py b/src/kognic/auth/requests/auth_session.py index 4958b44..6bf22a1 100644 --- a/src/kognic/auth/requests/auth_session.py +++ b/src/kognic/auth/requests/auth_session.py @@ -68,6 +68,8 @@ def __init__( token_endpoint=self.token_url, **kwargs, ) + self.oauth_session.register_compliance_hook("access_token_response", AuthClient.check_rate_limit) + self.oauth_session.register_compliance_hook("refresh_token_response", AuthClient.check_rate_limit) self._lock = threading.RLock()