Skip to content

Commit

Permalink
Merge pull request #110 from neel004/refresh-tokens-while-pagination
Browse files Browse the repository at this point in the history
Refresh tokens while pagination
  • Loading branch information
omarryhan authored Nov 21, 2022
2 parents 7806abd + b99037f commit f243183
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 8 additions & 4 deletions aiogoogle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ async def as_user(self, *requests, timeout=None, full_res=False, user_creds=None
timeout=timeout,
full_res=full_res,
raise_for_status=raise_for_status,
session_factory=self.session_factory
session_factory=self.session_factory,
auth_manager=self.oauth2
)

async def as_service_account(
Expand Down Expand Up @@ -296,7 +297,8 @@ async def as_service_account(
timeout=timeout,
full_res=full_res,
raise_for_status=raise_for_status,
session_factory=self.session_factory
session_factory=self.session_factory,
auth_manager=self.service_account_manager,
)

async def as_api_key(self, *requests, timeout=None, full_res=False, api_key=None, raise_for_status=True):
Expand Down Expand Up @@ -343,7 +345,8 @@ async def as_api_key(self, *requests, timeout=None, full_res=False, api_key=None
timeout=timeout,
full_res=full_res,
raise_for_status=raise_for_status,
session_factory=self.session_factory
session_factory=self.session_factory,
auth_manager=self.api_key_manager
)

async def as_anon(self, *requests, timeout=None, full_res=False, raise_for_status=True):
Expand Down Expand Up @@ -377,7 +380,8 @@ async def as_anon(self, *requests, timeout=None, full_res=False, raise_for_statu
timeout=timeout,
full_res=full_res,
raise_for_status=raise_for_status,
session_factory=self.session_factory
session_factory=self.session_factory,
auth_manager=None
)

def _get_session(self):
Expand Down
8 changes: 7 additions & 1 deletion aiogoogle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ class Response:
pipe_from (file object): class object to stream file content from
session_factory (aiogoogle.sessions.abc.AbstractSession): A callable implementation of aiogoogle's session interface
auth_manager (aiogoogle.auth.managers.ServiceAccountManager): Service account authorization manager.
"""

def __init__(
Expand All @@ -294,6 +296,7 @@ def __init__(
upload_file=None,
pipe_from=None,
session_factory=None,
auth_manager=None
):
if json and data:
raise TypeError("Pass either json or data, not both.")
Expand All @@ -310,6 +313,7 @@ def __init__(
self.upload_file = upload_file
self.pipe_from = pipe_from
self.session_factory = session_factory
self.auth_manager = auth_manager

@staticmethod
async def _next_page_generator(
Expand Down Expand Up @@ -338,7 +342,9 @@ async def _next_page_generator(
)
if next_req is not None:
async with session_factory() as sess:
prev_res = await sess.send(next_req, full_res=True)
await prev_res.auth_manager.refresh()
prev_res.auth_manager.authorize(next_req)
prev_res = await sess.send(next_req, full_res=True, auth_manager=prev_res.auth_manager)
else:
prev_res = None

Expand Down
2 changes: 2 additions & 0 deletions aiogoogle/sessions/aiohttp_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async def send(
full_res=False,
raise_for_status=True,
session_factory=None,
auth_manager=None
):
async def resolve_response(request, response):
data = None
Expand Down Expand Up @@ -92,6 +93,7 @@ async def resolve_response(request, response):
upload_file=upload_file,
pipe_from=pipe_from,
session_factory=session_factory,
auth_manager=auth_manager
)

async def fire_request(request):
Expand Down

0 comments on commit f243183

Please sign in to comment.