Skip to content

Commit 00b0880

Browse files
Small fixes
1 parent 0030521 commit 00b0880

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

oauthenticator/cilogon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def user_info_to_username(self, user_info):
299299
action = username_derivation.get("action")
300300

301301
if action == "strip_idp_domain":
302-
username = username.split("@")[0]
302+
username = username.split("@", 1)[0]
303303
elif action == "prefix":
304304
prefix = username_derivation["prefix"]
305305
username = f"{prefix}:{username}"
@@ -335,7 +335,7 @@ async def check_allowed(self, username, auth_model):
335335
f"Trying to login from an identity provider that was not allowed {selected_idp}",
336336
)
337337
raise web.HTTPError(
338-
500,
338+
403,
339339
"Trying to login using an identity provider that was not allowed",
340340
)
341341

@@ -355,7 +355,7 @@ async def check_allowed(self, username, auth_model):
355355
username_with_domain = self._get_username_from_claim_list(
356356
user_info, username_claims
357357
)
358-
user_domain = username_with_domain.split("@")[1]
358+
user_domain = username_with_domain.split("@", 1)[1]
359359
if user_domain in allowed_domains:
360360
return True
361361
else:

oauthenticator/globus.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,19 @@ async def check_allowed(self, username, auth_model):
274274
auth_model["admin"] = True
275275
return True
276276

277+
if self.identity_provider:
278+
user_info = auth_model["auth_state"][self.user_auth_state_key]
279+
domain = user_info.get(self.username_claim).split('@', 1)[-1]
280+
if domain != self.identity_provider:
281+
self.log.error(
282+
f"Trying to login from an identity provider that was not allowed {domain}",
283+
)
284+
raise HTTPError(
285+
403,
286+
f"This site is restricted to {self.identity_provider} accounts. "
287+
"Please link your account at app.globus.org/account.",
288+
)
289+
277290
# if allowed_users or allowed_globus_groups is configured, we deny users not part of either
278291
if self.allowed_users or self.allowed_globus_groups:
279292
if username in self.allowed_users:
@@ -320,14 +333,7 @@ def user_info_to_username(self, user_info):
320333

321334
# It's possible for identity provider domains to be namespaced
322335
# https://docs.globus.org/api/auth/specification/#identity_provider_namespaces # noqa
323-
username, domain = user_info.get(self.username_claim).split('@', 1)
324-
if self.identity_provider and domain != self.identity_provider:
325-
raise HTTPError(
326-
403,
327-
f"This site is restricted to {self.identity_provider} accounts. "
328-
"Please link your account at app.globus.org/account.",
329-
)
330-
return username
336+
return user_info.get(self.username_claim).split('@')[0]
331337

332338
def get_default_headers(self):
333339
return {"Accept": "application/json", "User-Agent": "JupyterHub"}

0 commit comments

Comments
 (0)