Cannot spawn server for user authenticated with 3rd party (KeyCloak)?

Context:
I have JupyterHub setup in a python venv on an EC2 running Ubunut 22.04 LTS. I made it following this guide: jupyterhub-the-hard-way/installation-guide-hard.md at 35ddfb49ad81771551c6549696ccec960564d5e4 · jupyterhub/jupyterhub-the-hard-way · GitHub

Users login to a URL (nginx reverse proxy that provides HTTPS) that redirects them to KeyCloak, which redirects them back to the home page of their Hub profile (the one where you can start your server).

Problem:
I’m not able to spawn a server using jupyterhub.spawner.SimpleLocalProcessSpawner even though I’ve ensured that a local user that matches the keycloak login exists (doing this via:

def pre_spawn_hook(spawner):
    username = spawner.user.name
    try:
        import pwd
        pwd.getpwnam(username)
    except KeyError:
        import subprocess
        subprocess.check_call(['useradd', '-ms', '/bin/bash', username])

c.Spawner.pre_spawn_hook = pre_spawn_hook

)

Instead, I notice the following errors in the log (via journalctl -u jupyterhub.service -b -e):

JupyterHub utils:91] Unexpected error connecting to <PRIVATE-EC2-IP>:8000 [Errno 22] Invalid argument
067 JupyterHub utils:91] Unexpected error connecting to <PRIVATE-EC2-IP>:8000 [Errno 22] Invalid argument

I believe this might be because of a misconfigured Conda environment, but I’m not sure how to fix this.

The guide referenced above mentions that users need to SSH into the server themselves and manage their own environments.

I would instead like for a python environment to be created on their behalf without them having to touch SSH or the server at all. How would I do that?

Would I have to use a different spawner?

Solved. Getting rid of the c.JupyterHub.spawner_class = 'jupyterhub.spawner.SimpleLocalProcessSpawner' line in the config allowed JupyterHub to launch the server via the default and the pre-spawn hook seems to still work for ensuring (creating if needed) the user that authenticated via the 3rd party.