mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-17 15:03:02 +00:00
Add @allow_unauthenticated decorators
This commit is contained in:
14
jupyterhub/singleuser/_decorator.py
Normal file
14
jupyterhub/singleuser/_decorator.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from typing import Any, Callable, TypeVar
|
||||
|
||||
try:
|
||||
from jupyter_server.auth.decorator import allow_unauthenticated
|
||||
except ImportError:
|
||||
FuncT = TypeVar("FuncT", bound=Callable[..., Any])
|
||||
|
||||
# if using an older jupyter-server version this can be a no-op,
|
||||
# as these do not support marking endpoints anyways
|
||||
def allow_unauthenticated(method: FuncT) -> FuncT:
|
||||
return method
|
||||
|
||||
|
||||
__all__ = ["allow_unauthenticated"]
|
@@ -51,6 +51,7 @@ from jupyterhub.utils import (
|
||||
url_path_join,
|
||||
)
|
||||
|
||||
from ._decorator import allow_unauthenticated
|
||||
from ._disable_user_config import _disable_user_config
|
||||
|
||||
SINGLEUSER_TEMPLATES_DIR = str(Path(__file__).parent.resolve().joinpath("templates"))
|
||||
@@ -68,6 +69,7 @@ def _exclude_home(path_list):
|
||||
|
||||
|
||||
class JupyterHubLogoutHandler(LogoutHandler):
|
||||
@allow_unauthenticated
|
||||
def get(self):
|
||||
hub_auth = self.identity_provider.hub_auth
|
||||
# clear token stored in single-user cookie (set by hub_auth)
|
||||
@@ -95,6 +97,10 @@ class JupyterHubOAuthCallbackHandler(HubOAuthCallbackHandler):
|
||||
def initialize(self, hub_auth):
|
||||
self.hub_auth = hub_auth
|
||||
|
||||
@allow_unauthenticated
|
||||
async def get(self):
|
||||
return await super().get()
|
||||
|
||||
|
||||
class JupyterHubIdentityProvider(IdentityProvider):
|
||||
"""Identity Provider for JupyterHub OAuth
|
||||
|
@@ -52,6 +52,7 @@ from ..utils import (
|
||||
make_ssl_context,
|
||||
url_path_join,
|
||||
)
|
||||
from ._decorator import allow_unauthenticated
|
||||
from ._disable_user_config import _disable_user_config, _exclude_home
|
||||
|
||||
# Authenticate requests with the Hub
|
||||
@@ -132,6 +133,7 @@ class JupyterHubLoginHandlerMixin:
|
||||
|
||||
|
||||
class JupyterHubLogoutHandlerMixin:
|
||||
@allow_unauthenticated
|
||||
def get(self):
|
||||
self.settings['hub_auth'].clear_cookie(self)
|
||||
self.redirect(
|
||||
@@ -147,6 +149,10 @@ class OAuthCallbackHandlerMixin(HubOAuthCallbackHandler):
|
||||
def hub_auth(self):
|
||||
return self.settings['hub_auth']
|
||||
|
||||
@allow_unauthenticated
|
||||
async def get(self):
|
||||
return await super().get()
|
||||
|
||||
|
||||
# register new hub related command-line aliases
|
||||
aliases = {
|
||||
|
Reference in New Issue
Block a user