Custom Login and Keycloak

Intially Iam using keycloack for jupyterhub authentication.
Later we integrated it in anther application so with custom auth I logged into Jupyterhub by hitting below url:
with below code

class MyAuthenticator(Authenticator):
        def _auto_login_default(self):
          return True
        async def authenticate(self, handler, data=None):
          user_id = handler.get_query_argument("userId", default="")
          if user_id == "sairam":
            return {name:user_id}
          ------other logic-----------
            return None
      c.JupyterHub.authenticator_class = MyAuthenticator

I have successfully integrated custom authentication with JupyterHub using the MyAuthenticator class and the URL parameter userId. However, I now need to implement a fallback mechanism to redirect users to the Keycloak login page when the userId parameter is not provided in the URL.

Any guidance on modifying the MyAuthenticator class to accommodate this new behavior would be greatly appreciated.

I guess you can use self.redirect(url, permanent)?

1 Like

If you return None from authenticate, it should send unauthenticated requests to the login_url. What behavior are you getting when you return None that’s not what you want?

As it is already using authenticator_class is MyAuthenticator
Iam unable to switch to the
c.JupyterHub.authenticator_class = ‘generic-oath’