After successful login using Azure AD Oauthenticator we are getting the full given name instead of the unique username so the local process spawner is failing to spawn with errors. How do we make the username as firstname.lastname so that the OS username will match for getpwnam() .:
[E 2022-11-23 05:04:19.937 JupyterHub user:832] Unhandled error starting xxxxxxx, xxxxxxx (xxxx)'s server: “getpwnam(): name not found: ‘xxxxxx, xxxxxx (xxxxx)’”
Traceback (most recent call last):
File “/data/opt/anaconda3/lib/python3.9/site-packages/jupyterhub/user.py”, line 747, in spawn
url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
File “/data/opt/anaconda3/lib/python3.9/site-packages/jupyterhub/spawner.py”, line 1664, in start
env = self.get_env()
File “/data/opt/anaconda3/lib/python3.9/site-packages/jupyterhub/spawner.py”, line 1611, in get_env
env = self.user_env(env)
File “/data/opt/anaconda3/lib/python3.9/site-packages/jupyterhub/spawner.py”, line 1598, in user_env
home = pwd.getpwnam(self.user.name).pw_dir
KeyError: “getpwnam(): name not found: ‘xxxxx, xxxxxx (xxxxxx)’”
These are the parms we set in /etc/jupyterhub/jupyterhub_config.py
import os
from oauthenticator.azuread import AzureAdOAuthenticator
Thanks for the reply! How would you figure out the fields in the Azure AD response within the ssl payload. And how do you change the field used as the username.
“Is the required username already available in your response? If so you change the field used as the username.”
Now I get the email address returned so getting closer. Just need to figure out how to get the upn firstname.lastname or may need to change config to ignore the @xyz.com suffix in the email address. Which parameter in the config can be used to remove the @xyz.com suffix using some regular expression or other means?
Hello @manics I tried above code but jupyterhub wont start and gave error below. Another other ideas?
File "/data1r10/opt/anaconda3/lib/python3.9/site-packages/traitlets/traitlets.py", line 2190, in validate
self.error(obj, value)
File "/data1r10/opt/anaconda3/lib/python3.9/site-packages/traitlets/traitlets.py", line 692, in error
raise TraitError(e)
traitlets.traitlets.TraitError: The 'username_claim' trait of an AzureAdOAuthenticator instance expected a unicode string, not the function 'get_username_from_userinfo'.
ok no problem, will try to see if can include the logic manually or wait until official release. I haven’t looked at the code much so if you can point me to the function to add some code for the simplest way to modify the email to remove the @xyz.com suffix that will be a great help.