mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Apply TLJH auth config with less assumptions
This commit is contained in:
@@ -149,27 +149,49 @@ def update_base_url(c, config):
|
|||||||
|
|
||||||
def update_auth(c, config):
|
def update_auth(c, config):
|
||||||
"""
|
"""
|
||||||
Set auth related configuration from YAML config file
|
Set auth related configuration from YAML config file.
|
||||||
|
|
||||||
Use auth.type to determine authenticator to use. All parameters
|
As an example, this function should update the following TLJH auth
|
||||||
in the config under auth.{auth.type} will be passed straight to the
|
configuration:
|
||||||
authenticators themselves.
|
|
||||||
|
```yaml
|
||||||
|
auth:
|
||||||
|
type: oauthenticator.github.GitHubOAuthenticator
|
||||||
|
GitHubOAuthenticator:
|
||||||
|
client_id: "..."
|
||||||
|
client_secret: "..."
|
||||||
|
oauth_callback_url: "..."
|
||||||
|
ArbitraryKey:
|
||||||
|
arbitrary_key: "..."
|
||||||
|
arbitrary_key_with_none_value:
|
||||||
|
```
|
||||||
|
|
||||||
|
by applying the following configuration:
|
||||||
|
|
||||||
|
```python
|
||||||
|
c.JupyterHub.authenticator_class = "oauthenticator.github.GitHubOAuthenticator"
|
||||||
|
c.GitHubOAuthenticator.client_id = "..."
|
||||||
|
c.GitHubOAuthenticator.client_secret = "..."
|
||||||
|
c.GitHubOAuthenticator.oauth_callback_url = "..."
|
||||||
|
c.ArbitraryKey.arbitrary_key = "..."
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that "auth.type" and "auth.ArbitraryKey.arbitrary_key_with_none_value"
|
||||||
|
are treated a bit differently. auth.type will always map to
|
||||||
|
c.JupyterHub.authenticator_class and any configured value being None won't
|
||||||
|
be set.
|
||||||
"""
|
"""
|
||||||
auth = config.get('auth')
|
tljh_auth_config = config['auth']
|
||||||
|
c.JupyterHub.authenticator_class = tljh_auth_config['type']
|
||||||
|
|
||||||
# FIXME: Make sure this is something importable.
|
for auth_key, auth_value in tljh_auth_config.items():
|
||||||
# FIXME: SECURITY: Class must inherit from Authenticator, to prevent us being
|
if auth_key == "type":
|
||||||
# used to set arbitrary properties on arbitrary types of objects!
|
continue
|
||||||
authenticator_class = auth['type']
|
traitlet_class_name = auth_key
|
||||||
# When specifying fully qualified name, use classname as key for config
|
traitlet_class_config = auth_value
|
||||||
authenticator_configname = authenticator_class.split('.')[-1]
|
traitlet_class_instance = getattr(c, traitlet_class_name)
|
||||||
c.JupyterHub.authenticator_class = authenticator_class
|
for config_name, config_value in traitlet_class_config.items():
|
||||||
# Use just class name when setting config. If authenticator is dummyauthenticator.DummyAuthenticator,
|
set_if_not_none(traitlet_class_instance, config_name, config_value)
|
||||||
# its config will be set under c.DummyAuthenticator
|
|
||||||
authenticator_parent = getattr(c, authenticator_class.split('.')[-1])
|
|
||||||
|
|
||||||
for k, v in auth.get(authenticator_configname, {}).items():
|
|
||||||
set_if_not_none(authenticator_parent, k, v)
|
|
||||||
|
|
||||||
|
|
||||||
def update_userlists(c, config):
|
def update_userlists(c, config):
|
||||||
|
|||||||
Reference in New Issue
Block a user