mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Support arbitrary authenticators
- Removes all need for special casing authenticators. - Install them in hub environment, directly start using them. - Consider if we should special case any *at all*
This commit is contained in:
@@ -125,3 +125,21 @@ def test_auth_firstuse():
|
||||
})
|
||||
assert c.JupyterHub.authenticator_class == 'firstuseauthenticator.FirstUseAuthenticator'
|
||||
assert c.FirstUseAuthenticator.create_users
|
||||
|
||||
|
||||
def test_auth_github():
|
||||
"""
|
||||
Test using GitHub authenticator, which is not explicitly special cased.
|
||||
"""
|
||||
c = apply_mock_config({
|
||||
'auth': {
|
||||
'type': 'oauthenticator.github.GitHubOAuthenticator',
|
||||
'GitHubOAuthenticator': {
|
||||
'client_id': 'something',
|
||||
'client_secret': 'something-else'
|
||||
}
|
||||
}
|
||||
})
|
||||
assert c.JupyterHub.authenticator_class == 'oauthenticator.github.GitHubOAuthenticator'
|
||||
assert c.GitHubOAuthenticator.client_id == 'something'
|
||||
assert c.GitHubOAuthenticator.client_secret == 'something-else'
|
||||
|
||||
@@ -70,13 +70,22 @@ def update_auth(c, config):
|
||||
'firstuse': 'firstuseauthenticator.FirstUseAuthenticator'
|
||||
}
|
||||
|
||||
authenticator_classname = authenticator_class_map[auth['type']]
|
||||
c.JupyterHub.authenticator_class = authenticator_classname
|
||||
if auth['type'] in authenticator_class_map:
|
||||
authenticator_class = authenticator_class_map[auth['type']]
|
||||
authenticator_configname = auth['type']
|
||||
else:
|
||||
# FIXME: Make sure this is something importable.
|
||||
# FIXME: SECURITY: Class must inherit from Authenticator, to prevent us being
|
||||
# used to set arbitrary properties on arbitrary types of objects!
|
||||
authenticator_class = auth['type']
|
||||
# When specifying fully qualified name, use classname as key for config
|
||||
authenticator_configname = authenticator_class.split('.')[-1]
|
||||
c.JupyterHub.authenticator_class = authenticator_class
|
||||
# Use just class name when setting config. If authenticator is dummyauthenticator.DummyAuthenticator,
|
||||
# its config will be set under c.DummyAuthenticator
|
||||
authenticator_parent = getattr(c, authenticator_classname.split('.')[-1])
|
||||
authenticator_parent = getattr(c, authenticator_class.split('.')[-1])
|
||||
|
||||
for k, v in auth[auth['type']].items():
|
||||
for k, v in auth.get(authenticator_configname, {}).items():
|
||||
set_if_not_none(authenticator_parent, k, v)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user