# OAuth redirect fails with JupyterHub in API-only mode

**URL:** <https://discourse.jupyter.org/t/oauth-redirect-fails-with-jupyterhub-in-api-only-mode/27275>\
**Category:** JupyterHub\
**Tags:** jupyterhub, how-to, help-wanted\
**Created:** [July 29, 2024, 10:51pm UTC](https://discourse.jupyter.org/t/oauth-redirect-fails-with-jupyterhub-in-api-only-mode/27275 "2024-07-29T22:51:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktaletsk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/ktaletsk/32/528_2.png) [@ktaletsk](https://discourse.jupyter.org/u/ktaletsk)\
**Post date:** [July 29, 2024, 10:51pm UTC](https://discourse.jupyter.org/t/oauth-redirect-fails-with-jupyterhub-in-api-only-mode/27275/1 "2024-07-29T22:51:36Z")

</div>

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

```auto
c.JupyterHub.hub_routespec = "/hub"

```

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

When I switch to

```auto
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.

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [July 30, 2024, 4:36pm UTC](https://discourse.jupyter.org/t/oauth-redirect-fails-with-jupyterhub-in-api-only-mode/27275/2 "2024-07-30T16:36:35Z")

</div>

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:

> **[JupyterHub and OAuth](https://jupyterhub.readthedocs.io/en/stable/explanation/oauth.html)**
>
> JupyterHub uses OAuth 2 as an internal mechanism for authenticating users. As such, JupyterHub itself always functions as an OAuth provider. You can find out more about what that means below. Addit...
