@@ -165,10 +165,6 @@ def _revoke_tokens_on_logout_default(self):
165
165
their UUIDs. Setting this will add the Globus Groups scope."""
166
166
).tag (config = True )
167
167
168
- @staticmethod
169
- def check_user_in_groups (member_groups , allowed_groups ):
170
- return bool (set (member_groups ) & set (allowed_groups ))
171
-
172
168
async def pre_spawn_start (self , user , spawner ):
173
169
"""Add tokens to the spawner whenever the spawner starts a notebook.
174
170
This will allow users to create a transfer client:
@@ -230,11 +226,8 @@ def build_auth_state_dict(self, token_info, user_info):
230
226
self .user_auth_state_key : user_info ,
231
227
}
232
228
233
- # FIXME: Should we persist info about user groups in auth model
234
- # to be consistent with what's happening in bitbucket.py
235
- # where the `auth_model` is updated with `user_teams`.
236
- async def get_users_groups_ids (self , tokens ):
237
- user_group_ids = set ()
229
+ async def _fetch_users_groups (self , tokens ):
230
+ user_groups = set ()
238
231
# Get Groups access token, may not be in dict headed to auth state
239
232
for token_dict in tokens :
240
233
if token_dict ['resource_server' ] == 'groups.api.globus.org' :
@@ -247,9 +240,9 @@ async def get_users_groups_ids(self, tokens):
247
240
)
248
241
# Build set of Group IDs
249
242
for group in groups_resp :
250
- user_group_ids .add (group ['id' ])
243
+ user_groups .add (group ['id' ])
251
244
252
- return user_group_ids
245
+ return user_groups
253
246
254
247
async def check_allowed (self , username , auth_model ):
255
248
"""
@@ -274,7 +267,7 @@ async def check_allowed(self, username, auth_model):
274
267
user_info = auth_model ["auth_state" ][self .user_auth_state_key ]
275
268
domain = user_info .get (self .username_claim ).split ('@' , 1 )[- 1 ]
276
269
if domain != self .identity_provider :
277
- self .log .error (
270
+ self .log .warning (
278
271
f"Trying to login from an identity provider that was not allowed { domain } " ,
279
272
)
280
273
raise HTTPError (
@@ -289,14 +282,8 @@ async def check_allowed(self, username, auth_model):
289
282
if username in self .allowed_users :
290
283
return True
291
284
if self .allowed_globus_groups :
292
- tokens = self .get_globus_tokens (
293
- auth_model ["auth_state" ]["token_response" ]
294
- )
295
- user_group_ids = await self .get_users_groups_ids (tokens )
296
-
297
- if self .check_user_in_groups (
298
- user_group_ids , self .allowed_globus_groups
299
- ):
285
+ user_groups = auth_model ["auth_state" ]["globus_groups" ]
286
+ if any (user_groups & self .allowed_globus_groups ):
300
287
return True
301
288
self .log .warning (f"{ username } not in an allowed Globus Group" )
302
289
@@ -315,18 +302,20 @@ async def update_auth_model(self, auth_model):
315
302
`admin_globus_groups`. Note that leaving it at None makes users able to
316
303
retain an admin status while setting it to False makes it be revoked.
317
304
"""
318
- if auth_model ["admin" ] is True :
305
+ user_groups = set ()
306
+ if self .allowed_globus_groups or self .admin_globus_groups :
307
+ tokens = self .get_globus_tokens (auth_model ["auth_state" ]["token_response" ])
308
+ user_groups = await self ._fetch_users_groups (tokens )
309
+ auth_model ["auth_state" ]["globus_groups" ] = user_groups
310
+
311
+ if auth_model ["admin" ]:
312
+ # auth_model["admin"] being True means the user was in admin_users
319
313
return auth_model
320
314
321
315
if self .admin_globus_groups :
322
- tokens = self .get_globus_tokens (auth_model ["auth_state" ]["token_response" ])
323
- # If any of these configurations are set, user must be in the allowed or admin Globus Group
324
- user_group_ids = await self .get_users_groups_ids (tokens )
325
- # Admin users are being managed via Globus Groups
326
- # Default to False
327
- auth_model ["admin" ] = False
328
- if self .check_user_in_groups (user_group_ids , self .admin_globus_groups ):
329
- auth_model ["admin" ] = True
316
+ # admin status should in this case be True or False, not None
317
+ auth_model ["admin" ] = any (user_groups & self .admin_globus_groups )
318
+
330
319
return auth_model
331
320
332
321
def user_info_to_username (self , user_info ):
0 commit comments