Change auto created username pattern

Due to oauth2 configs our users’ usernames emulate the email pattern user@domain.com. Home directories reflect the entire email address, i.e., jupyter-user@domain.com

I’d prefer to constrain usernames to just the user portion of the mail to the left of @. This would make it easier to login, eliminate uglier urls, etc.

Is there an easy way to achieve this? Does it require extending the User class?

1 Like

You can subclass your authenticator class, and modify the returned username:
https://jupyterhub.readthedocs.io/en/stable/api/auth.html#jupyterhub.auth.Authenticator.authenticate

1 Like

I’m also interested in stripping out the “jupyter-” part from the usernames. The doc string for Authenticators — JupyterHub 2.1.1 documentation didn’t give me an obvious way to do this but if I work it out i’ll share here

The username is returned by whatever authenticator you’re using- there are lots of them! Some authenticators let you customise the returned username. If they don’t then you can override the class as mentioned in my previous post.

Thanks for the reply. I’m using tljh which uses GitHub - jupyterhub/firstuseauthenticator: JupyterHub Authenticator that lets users set passwords when they first log in by default. I couldn’t see where the jupyter- prefix is getting set for the username in firstuseauthenticator/firstuseauthenticator.py at 5d572408f28e90ae605a6152a03045d93ba987c0 · jupyterhub/firstuseauthenticator · GitHub

I should be able to be pretty flexible on the choice of authenticator and it would be great if returns the same as that goes into the --admin flag e.g. ray.bell. I could see what username is returned with DummyAuthenticator jupyterhub/auth.py at 3ed345f4960f083b2d35c72b330254aa3cf31fe9 · jupyterhub/jupyterhub · GitHub

It looks like it’s hardcoded in TLJH:

1 Like