@@ -297,30 +297,39 @@ async def check_allowed(self, username, auth_model):
297
297
if auth_model is None :
298
298
return True
299
299
300
+ if await super ().check_allowed (username , auth_model ):
301
+ return True
302
+
303
+ if self .allowed_globus_groups :
304
+ user_groups = set (auth_model ["auth_state" ]["globus_groups" ])
305
+ if user_groups & self .allowed_globus_groups :
306
+ return True
307
+ self .log .warning (f"{ username } not in an allowed Globus Group" )
308
+
309
+ # users should be explicitly allowed via config, otherwise they aren't
310
+ return False
311
+
312
+ async def check_blocked_users (self , username , authentication ):
313
+ """Check if the user should be blocked
314
+
315
+ Called _before_ checking if the user should be allowed
316
+ """
317
+ # any restrictions on access go here - allow config only _grants_ access,
318
+ # restrictions belong in the `block` stage
300
319
# before considering allowing a username by being recognized in a list
301
320
# of usernames or similar, we must ensure that the authenticated user is
302
321
# from an allowed identity provider domain.
303
322
if self .identity_provider :
304
323
# It's possible for identity provider domains to be namespaced
305
324
# https://docs.globus.org/api/auth/specification/#identity_provider_namespaces
306
- user_info = auth_model ["auth_state" ][self .user_auth_state_key ]
325
+ user_info = authentication ["auth_state" ][self .user_auth_state_key ]
307
326
user_domain = user_info .get (self .username_claim ).split ('@' , 1 )[- 1 ]
308
327
if user_domain != self .identity_provider :
309
328
message = f"This site is restricted to { self .identity_provider } accounts. Link your account at app.globus.org/account."
310
329
self .log .warning (message )
311
330
raise web .HTTPError (403 , message )
312
331
313
- if await super ().check_allowed (username , auth_model ):
314
- return True
315
-
316
- if self .allowed_globus_groups :
317
- user_groups = set (auth_model ["auth_state" ]["globus_groups" ])
318
- if user_groups & self .allowed_globus_groups :
319
- return True
320
- self .log .warning (f"{ username } not in an allowed Globus Group" )
321
-
322
- # users should be explicitly allowed via config, otherwise they aren't
323
- return False
332
+ return super ().check_blocked_users (username , authentication )
324
333
325
334
async def update_auth_model (self , auth_model ):
326
335
"""
0 commit comments