Skip to content

Commit

Permalink
clarify that web.HTTPError may be raised anywhere in the auth process
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Mar 4, 2024
1 parent 7f8eef5 commit be1848f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions jupyterhub/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,7 @@ def normalize_username(self, username):
def check_allowed(self, username, authentication=None):
"""Check if a username is allowed to authenticate based on configuration
Return True if username is allowed, False otherwise. Subclasses can also
raise a `web.HTTPError(403, message)` to immediately *deny* access and show
the end user the given message.
Return True if username is allowed, False otherwise.
No allowed_users set means any username is allowed.
Expand All @@ -466,6 +464,18 @@ def check_allowed(self, username, authentication=None):
.. versionchanged:: 1.2
Renamed check_whitelist to check_allowed
Args:
username (str):
The normalized username
authentication (dict):
The authentication model, as returned by `.authenticate()`.
Returns:
allowed (bool):
Whether the user is allowed
Raises:
web.HTTPError(403):
Raising HTTPErrors directly allows customizing the message shown to the user.
"""
if not self.allowed_users:
# No allowed set means any name is allowed
Expand All @@ -487,6 +497,18 @@ def check_blocked_users(self, username, authentication=None):
.. versionchanged:: 1.2
Renamed check_blacklist to check_blocked_users
Args:
username (str):
The normalized username
authentication (dict):
The authentication model, as returned by `.authenticate()`.
Returns:
allowed (bool):
Whether the user is allowed
Raises:
web.HTTPError(403, message):
Raising HTTPErrors directly allows customizing the message shown to the user.
"""
if not self.blocked_users:
# No block list means any name is allowed
Expand Down Expand Up @@ -612,6 +634,12 @@ async def authenticate(self, handler, data):
It must return the username on successful authentication,
and return None on failed authentication.
Subclasses can also raise a `web.HTTPError(403, message)`
in order to halt the authentication process
and customize the error message that will be shown to the user.
This error may be raised anywhere in the authentication process
(`authenticate`, `check_allowed`, `check_blocked_users`).
Checking allowed_users/blocked_users is handled separately by the caller.
.. versionchanged:: 0.8
Expand All @@ -634,6 +662,9 @@ async def authenticate(self, handler, data):
- `groups`, the list of group names the user should be a member of,
if Authenticator.manage_groups is True.
`groups` MUST always be present if manage_groups is enabled.
Raises:
web.HTTPError(403):
Raising errors directly allows customizing the message shown to the user.
"""

def pre_spawn_start(self, user, spawner):
Expand Down

0 comments on commit be1848f

Please sign in to comment.