Jupyterhub - custom authenticator - how to override default /login handler

1,121 views
Skip to first unread message

Carl Waldbieser

unread,
Nov 3, 2015, 10:03:33 PM11/3/15
to Project Jupyter

I'm writing a custom authenticator for jupyterhub that assumes the hub is behind an authenticating proxy and and that the authenticated username will be present in an HTTP header (e.g. REMOTE_USER).

I have the authenticator working, but I am not sure how to arrange things so that the main "/login" resource triggers it.
Currently, my authenticator's `get_handlers()` method looks like this:

    def get_handlers(self, app):
        return [
            (r'/remote_user_login', RemoteUserLoginHandler),
        ]

I can browse to "/remote_user_login", and I am logged in by virtue of the REMOTE_USER header populated by my proxy.  But I'd like the default "/login" resource to invoke my login handler.

Thanks,
Carl Waldbieser

MinRK

unread,
Nov 4, 2015, 5:02:04 AM11/4/15
to jup...@googlegroups.com

Do you want to change the login URL for a reason? Why not use (r'/login', RemoteUserLoginHandler)? You can override the login url by overriding the login_url(base_url) method, but I suspect putting your login handler on the default URL is the right thing to do, instead.

-MinRK

Carl Waldbieser

unread,
Nov 4, 2015, 2:39:52 PM11/4/15
to Project Jupyter
I tried returning `(r'/login', RemoteUserHandler)` from my authenticator's `get_handlers()` method (currently is "/remote_user_login" [1]), but when I press the "logout" button, I get redirected to the original login form (not automatically logged in as I would expect).  I wasn't sure you could return `r'/login'` and expect it to be overridden.

Thanks,
Carl

[1] https://github.com/cwaldbieser/jhub_remote_user_authenticator/blob/master/remote_user/remote_user_auth.py

MinRK

unread,
Nov 5, 2015, 4:44:08 AM11/5/15
to jup...@googlegroups.com
On Wed, Nov 4, 2015 at 8:39 PM, Carl Waldbieser <cwald...@gmail.com> wrote:
I tried returning `(r'/login', RemoteUserHandler)` from my authenticator's `get_handlers()` method (currently is "/remote_user_login" [1]), but when I press the "logout" button, I get redirected to the original login form (not automatically logged in as I would expect).  I wasn't sure you could return `r'/login'` and expect it to be overridden.

It should work. Can you check with the latest version of JupyterHub?

-MinRK
 

Thanks,
Carl

[1] https://github.com/cwaldbieser/jhub_remote_user_authenticator/blob/master/remote_user/remote_user_auth.py

On Wednesday, November 4, 2015 at 5:02:04 AM UTC-5, Min RK wrote:

Do you want to change the login URL for a reason? Why not use (r'/login', RemoteUserLoginHandler)? You can override the login url by overriding the login_url(base_url) method, but I suspect putting your login handler on the default URL is the right thing to do, instead.

-MinRK

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/e76a5902-e493-46da-9f3a-3f6f06ce3eef%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Carl Waldbieser

unread,
Nov 5, 2015, 12:12:21 PM11/5/15
to Project Jupyter
I pull up to HEAD on master, and I still get the main login page instead of my custom authenticator redirecting.

Should I open an issue?

Thanks,
Carl

Carl Waldbieser

unread,
Nov 5, 2015, 1:34:25 PM11/5/15
to Project Jupyter

Actually, I found at the bottom of `jupyterhub/handlers/login.py` there is a bit of code:

# Only logout is a default handler.
default_handlers
= [
   
(r"/login", LoginHandler),
   
(r"/logout", LogoutHandler),
]

The comment doesn't seem to match the code.  If I comment out the "/login" handler, my own "/login" handler is installed.  I can see in `app.py` where the default is installed *before* any handlers from the authenticator.

Thanks,
Carl

MinRK

unread,
Nov 5, 2015, 3:46:01 PM11/5/15
to jup...@googlegroups.com
Ah, you are right. I don't think that's quite how it should work. Right now, you would have to put your handler on a different URL *and* override the login_url method. I'll clean that up. Feel free to open an issue.

-MinRK

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages