Wildcard mapping in AzureAdOAuthenticator.username_map

Hello,

While I can do mapping for individual users from email to local user, I am interested in doing a wildcard mapping for all users for example some regex or * like below:
c.AzureAdOAuthenticator.username_map = {
‘*@xyz.com’: ‘*’
}

The expected result is that any username like fname.lname@xyz.com is mapped to fname.lname without having to add each user one by one in the username_map. Thx!

You can subclass the authenticator to override normalize_username which is a function:

Thanks @manics this worked using a subclass of LocalAzureAdOAuthenticator in the /etc/jupyterhub/jupyterhub_config.py as below:

###########Added the AZUREAD OAuth related stuff #########################
import os
from oauthenticator.azuread import LocalAzureAdOAuthenticator, AzureAdOAuthenticator

class myazureadoauthenticator(LocalAzureAdOAuthenticator):

      def normalize_username(self, username):
          print('DEBUG>>>>> inside normalize_username()...: ' , str(username))
          return username.lower().split('@')[0]

#c.JupyterHub.authenticator_class = AzureAdOAuthenticator
c.JupyterHub.authenticator_class = myazureadoauthenticator
c.Application.log_level = 'DEBUG'
c.AzureAdOAuthenticator.tenant_id = os.environ.get('AAD_TENANT_ID')
c.AzureAdOAuthenticator.client_id = 'redactedxxxxx-xxxxx-xxxxx'
c.AzureAdOAuthenticator.client_secret = 'redactedxxxxx-xxxxx-xxxxx'
c.AzureAdOAuthenticator.oauth_callback_url = 'https://myjupyterhuburlxxxx.com:8000/hub/oauth_callback'
c.AzureAdOAuthenticator.scope = ['openid', 'profile', 'email']
c.AzureAdOAuthenticator.username_claim = 'unique_name'
c.AzureAdOAuthenticator.normalize_username = True

########################### END OAUTH STUFF #####################

But I am not very clear why the LocalAzureAdOAuthenticator works but when I tried to custom subclass AzureAdOAuthenticator it didnt work. Or why we specify c.AzureAdOAuthenticator.normalize_username = True instead of the custom c.myazureadoauthenticator.normalize_username = True .

normalize_username is a function not a variable, and you’ve already overridden it in your custom class. Is there a doc somewhere that told you to set it to True?

No I removed the line c.AzureAdOAuthenticator.normalize_username = True
and it still works with the custom override so its not needed. Not sure where I saw it earlier. But why is the Local one LocalAzureAdOAuthenticator needed to make it work and what is the difference with AzureAdOAuthenticator .