Skip to content

Commit

Permalink
Merge pull request #133 from omarryhan/fix-refresh-error
Browse files Browse the repository at this point in the history
Fix refresh error
  • Loading branch information
omarryhan authored Oct 25, 2023
2 parents 225bc18 + db3908f commit d6432ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aiogoogle/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion aiogoogle/auth/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions aiogoogle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 already exist
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
Expand Down

0 comments on commit d6432ac

Please sign in to comment.