How to create a dictionary authenticator?

Hi,
I try to add a list of users and passwords to jupyterhub_config.py. Based on the docs
https://jupyterhub.readthedocs.io/en/stable/reference/authenticators.html#how-the-base-authenticator-works
I’ve tried the following

from jupyterhub.auth import Authenticator

class DictionaryAuthenticator(Authenticator):

    passwords = {'peter':'777'}
        
    async def authenticate(self, handler, data):
        if self.passwords.get(data['username']) == data['password']:
            return data['username']

c.JupyterHub.authenticator_class = 'DictionaryAuthenticator'

But when starting the container it throws the following error:

jupyterhub     |       File "/srv/jupyterhub/jupyterhub_config.py", line 55, in <module>
jupyterhub     |         from jupyterhub.auth import Authenticator
jupyterhub     |     ModuleNotFoundError: No module named 'jupyterhub'

What is the correct way to add this dictionary authenticator?
TIA!
Alex

It looks like you don’t have jupyterhub installed.

Try:

pip install jupyterhub

in your virtualenv.

Hey,

thank you! That’s it.
But how should I refer to this new class:

c.JupyterHub.authenticator_class = 'Authenticator'

leads to the error

....instance must be a type, but 'Authenticator' could not be imported.....

Same error by using

c.JupyterHub.authenticator_class = 'DictionaryAuthenticator'

TIA!
Alex

Since your Class is defined directly in the jupyterhub_config.py, you can try without quotes :

c.JupyterHub.authenticator_class = DictionaryAuthenticator
2 Likes

Perfect!
It’s working :slight_smile: