CustomAuthenticator

We are trying to use JWT token to login into jupyterhub. We wrote a custome authenticator class to validate the user id. we have imported the same in the jupyter_config.py. We have modified the TLJH config as well to indicate custom authenticator. however it is not working and also not getting any logs . How to resolve it.

Our need is to allow user to launch jupyterhub from our website , where user should not be asked for again user id and password.

suggest me way to verify whether the custom authenticator is getting invoked or not

You can add log lines in authenticate() method in the custom authenticator and they should be logged to your Hub logs.

1 Like

We tried that as well, added loggin line in the custom authenticator, but nothing printed in the logs and no error as well. Thats the reason we are unable to identify whether it is getting invoked or not, even we added print lines before and after while setting up the parameterā€¦c.JupyterHub.authenticator_class = ā€˜custom_authenticator.CustomAuthenticatorā€™, it is printing the before and after message. but the custom authenticator was not executed.

our code - CustomAuthenticator: from jupyterhub.auth import Authenticator

class CustomAuthenticator(Authenticator):
async def authenticate(self, handler, data):
# Extract user ID from data (e.g., JSON data sent by your web application)
user_id = data.get(ā€˜user_idā€™)

    # Debugging: Print the received user ID
    print(f"Received user ID: {user_id}")

    # Perform any necessary authentication logic here
    if is_valid_user_id(user_id):
        # Debugging: Print a message for successful authentication
        print(f"User ID {user_id} is authenticated.")
        return {
            'name': user_id,
            'auth_state': {
                'user_id': user_id,
                # Add other relevant user data if needed
            }
        }
    else:
        # Debugging: Print a message for failed authentication
        print(f"User ID {user_id} is not valid. Authentication failed.")
        return None

Could you try replacing print by self.log.info? If you use Hub logger, they will be logged to hub logs!

Is this problem solved.