diff --git a/oauthenticator/google.py b/oauthenticator/google.py index 9a568926..fdc50230 100644 --- a/oauthenticator/google.py +++ b/oauthenticator/google.py @@ -4,7 +4,6 @@ import os -import aiohttp from jupyterhub.auth import LocalAuthenticator from tornado.auth import GoogleOAuth2Mixin from tornado.web import HTTPError @@ -374,19 +373,15 @@ async def _fetch_member_groups( if not hasattr(self, 'credentials'): self.credentials = await self._setup_credentials(user_email_domain) - headers = {'Authorization': f'Bearer {self.credentials.token}'} - - async with aiohttp.ClientSession() as session: - async with session.get( - f'https://www.googleapis.com/admin/directory/v1/groups?userKey={member_email}', - headers=headers, - ) as resp: - group_data = await resp.json() - checked_groups = checked_groups or set() processed_groups = processed_groups or set() - resp = self.service.groups().list(userKey=member_email).execute() + headers = {'Authorization': f'Bearer {self.credentials.token}'} + url = f'https://www.googleapis.com/admin/directory/v1/groups?userKey={member_email}' + group_data = await self.httpfetch( + url, headers=headers, label="fetching google groups" + ) + member_groups = { g['email'].split('@')[0] for g in group_data.get('groups', []) @@ -399,7 +394,6 @@ async def _fetch_member_groups( if self.include_nested_groups: for group in member_groups: - if group in processed_groups: continue processed_groups.add(group)