Skip to content

Commit

Permalink
Use base httpfetch
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdnbradford committed Oct 3, 2024
1 parent 09e863c commit ebba631
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions oauthenticator/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os

import aiohttp
from jupyterhub.auth import LocalAuthenticator
from tornado.auth import GoogleOAuth2Mixin
from tornado.web import HTTPError
Expand Down Expand Up @@ -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', [])
Expand All @@ -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)
Expand Down

0 comments on commit ebba631

Please sign in to comment.