OAuth redirect fails with JupyterHub in API-only mode

Hi there,

I am trying JupyterHub’s API-only mode with the latest OAuthenticator and getting 404 error

My JupyterHub image is based on quay.io/jupyterhub/jupyterhub:5.0.0 and is using oauthenticator==16.3.1.

While I have

c.JupyterHub.hub_routespec = "/hub"

everything works as expected, but UI is shown (as expected)

When I switch to

c.JupyterHub.hub_routespec = "/hub/api/"

JupyterHub UI is now hidden.
I then successfully start a new singleuser server using the API.
When I navigate to the server in my browser:
<HUB URL>/user/<USERNAME>/<SERVERNAME>, I am being redirected to
<HUB URL>/hub/api/oauth2/authorize?client_id=jupyterhub-user-<USERNAME_ESCAPED>-<SERVERNAME_ESCAPED>&redirect_uri=/user/<USERNAME>/<SERVERNAME>/oauth_callback&response_type=code&state=<STATE>, which then redirects to
<HUB URL>/hub/login?next=/hub/api/oauth2/authorize?client_id=jupyterhub-user-<USERNAME_ESCAPED>-<SERVERNAME_ESCAPED>&redirect_uri=/user/<USERNAME>/<SERVERNAME>/oauth_callback&response_type=code&state=<STATE> which returns 404.
I assume, this is because /hub/login cannot be served while /hub/api/ was chosen as a routespec. Is it possible to run JupyterHub in API-only mode and still access singleuser servers with OAuth2?

One more thing to note, if I accessed the server prior to setting hub_routespec to "/hub/api/", I can still access it without issues right after I do. I assume some cookies are plauing the role, as it does not work in incognito tab.

I think that’s expected. Logging in to JupyterHub requires the user interface, if you’re running in API only mode you’ll need to authenticate the user some other way.

It’s probably working when you login with full access, then switch to API only mode, because you’ll have some cookies which are still valid.

Your can read about the full login process here: