From 3569a042e96678ea07cdd73d38c16b524476be20 Mon Sep 17 00:00:00 2001 From: Omar Ryhan Date: Wed, 25 Oct 2023 23:43:01 +0300 Subject: [PATCH 1/3] fix issue where user creds aren't being refreshed by client --- aiogoogle/auth/managers.py | 2 +- aiogoogle/client.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/aiogoogle/auth/managers.py b/aiogoogle/auth/managers.py index 935fb1c..fad48bb 100644 --- a/aiogoogle/auth/managers.py +++ b/aiogoogle/auth/managers.py @@ -626,7 +626,7 @@ async def refresh(self, user_creds, client_creds=None): """ client_creds = client_creds or self.client_creds - if not self.is_expired(user_creds): + if user_creds.get("expires_at") and not self.is_expired(user_creds): return False, user_creds request = self._build_refresh_request(user_creds, client_creds) diff --git a/aiogoogle/client.py b/aiogoogle/client.py index a7bd148..4f4efaf 100644 --- a/aiogoogle/client.py +++ b/aiogoogle/client.py @@ -240,14 +240,12 @@ async def as_user(self, *requests, timeout=None, full_res=False, user_creds=None if user_creds is None: raise TypeError("No user credentials were found") - # Refresh credentials - if user_creds.get("expires_at") is None: - is_refreshed, user_creds = await self.oauth2.refresh( - user_creds, client_creds=self.client_creds - ) - # Set refreshed user_creds if ones were already existing - if is_refreshed and self.user_creds is not None: - self.user_creds = user_creds + is_refreshed, user_creds = await self.oauth2.refresh( + user_creds, client_creds=self.client_creds + ) + # Set refreshed user_creds if ones were already existing + if is_refreshed and self.user_creds is not None: + self.user_creds = user_creds authorized_requests = [ self.oauth2.authorize(request, user_creds) for request in requests From 79036102a85c36774eafa0e6c51cb731c864761a Mon Sep 17 00:00:00 2001 From: Omar Ryhan Date: Wed, 25 Oct 2023 23:43:34 +0300 Subject: [PATCH 2/3] bump version --- aiogoogle/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogoogle/__version__.py b/aiogoogle/__version__.py index 5ad4c43..ed1595c 100644 --- a/aiogoogle/__version__.py +++ b/aiogoogle/__version__.py @@ -2,7 +2,7 @@ __about__ = "Async Google API client" __description__ = __about__ __url__ = "https://github.com/omarryhan/aiogoogle" -__version_info__ = ("5", "5", "0") +__version_info__ = ("5", "6", "0") __version__ = ".".join(__version_info__) __author__ = "Omar Ryhan" __author_email__ = "omarryhan@gmail.com" From db3908f52ac57baf55ccffa5857375e9c6460839 Mon Sep 17 00:00:00 2001 From: Omar Ryhan Date: Wed, 25 Oct 2023 23:44:33 +0300 Subject: [PATCH 3/3] comment --- aiogoogle/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogoogle/client.py b/aiogoogle/client.py index 4f4efaf..a2fedeb 100644 --- a/aiogoogle/client.py +++ b/aiogoogle/client.py @@ -243,7 +243,7 @@ async def as_user(self, *requests, timeout=None, full_res=False, user_creds=None is_refreshed, user_creds = await self.oauth2.refresh( user_creds, client_creds=self.client_creds ) - # Set refreshed user_creds if ones were already existing + # Set refreshed user_creds if ones already exist if is_refreshed and self.user_creds is not None: self.user_creds = user_creds