Configuring the generic oauth authenticator with a callable() as username_key in the config.yaml

I’m trying to configure the generic oauth authenticator with a callable() as username_key.
I’ve tried defining the callable function under hub.extraConfig:

hub:
  extraConfig:
    dp_username_key.py: |
      def get_feide_userid(response):
        return ([s for s in response['dataporten-userid_sec'] if 'feide' in s][0].split(':')[1])

And set the auth.custom.config.username_key to function name:

auth:
  type: custom
  custom:
    className: oauthenticator.generic.GenericOAuthenticator
    config:
      login_service: "Dataporten/Feide"
      ...
      username_key: get_feide_userid

The authentication works if I use a “static” value in username_key, but when I try with the callable() the hub logs indicate that it tries to match the string “get_feide_userid” to a field in the response rather than calling the function.
Is there some way to tell the config that username_key is a callable function and not a string?

I found a solution :slight_smile:
I moved all the configuration of the generic oauthenticator to hub.extraConfig

hub:
  extraConfig:
    10_dp_username_key.py: |
      def get_feide_userid(response):
        return ([s for s in response['dataporten-userid_sec'] if 'feide' in s][0].split(':')[1].split('@')[0])
    20_authenticator.py: |
      from oauthenticator.generic import GenericOAuthenticator
      c.JupyterHub.authenticator_class = GenericOAuthenticator
      c.GenericOAuthenticator.login_service = 'Dataporten/Feide'
      ...
      c.GenericOAuthenticator.username_key = get_feide_userid
1 Like