# Next Parameter Lost After Login via OIDC OAuth

**URL:** <https://discourse.jupyter.org/t/next-parameter-lost-after-login-via-oidc-oauth/34042>\
**Category:** discuss\
**Tags:** jupyterhub, how-to\
**Created:** [March 24, 2025, 11:37am UTC](https://discourse.jupyter.org/t/next-parameter-lost-after-login-via-oidc-oauth/34042 "2025-03-24T11:37:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavel-it4i](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/pavel-it4i/32/18068_2.png) [@pavel-it4i](https://discourse.jupyter.org/u/pavel-it4i)\
**Post date:** [March 24, 2025, 11:37am UTC](https://discourse.jupyter.org/t/next-parameter-lost-after-login-via-oidc-oauth/34042/1 "2025-03-24T11:37:11Z")

</div>

We want to provide users with a link that redirects them to a specific notebook after logging in. However, the `next` parameter in the URL is lost after a successful login, and the user is taken to the default page instead.

Is there a way to preserve the `next` parameter so that users are redirected correctly? Alternatively, would using `/user-redirect/...` be a better approach?

Thanks in advance for any suggestions!

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [March 26, 2025, 8:08am UTC](https://discourse.jupyter.org/t/next-parameter-lost-after-login-via-oidc-oauth/34042/2 "2025-03-26T08:08:55Z")

</div>

> [@pavel-it4i](#):
>
> would using `/user-redirect/...` be a better approach?

Quite likely, yes. If the URL you want users to arrive at is a URL on their own server once it’s running, that’s precisely what `/user-redirect/` is for. e.g. `https://jupyterhub.example.edu/user-redirect/lab/tree/subdir/some-notebook.ipynb` should ultimately take users to `subdir/some-notebook.ipynb` in their server, logging in if they aren’t logged in, and starting their server if it’s not running.

If this is more or less a single-purpose Hub, you could also make this your “default url” that users go to after login even _without_ a specially prepared link, rather than the Hub home page:

```python
c.JupyterHub.default_url = '/user-redirect/lab/tree/some-notebook.ipynb'

```

> [@pavel-it4i](#):
>
> Is there a way to preserve the `next` parameter so that users are redirected correctly?

`next` on the login page is generally preserved through the login process, but setting it directly would be unusual. Usually you share a link directly to the target resource, and `next` is populated during the redirect to login if not already logged in. What is the URL that you are using for next, and what URL are you sharing with `?next=...`? Can you share some logs? There is some sanitization of `next` to make sure you cannot redirect _outside_ jupyterhub, and it’s possible an absolute URL (as opposed to purely a path) might get rejected. These sanitizations may be why next is lost and if so, it should be logged.

---

<div class="post-metadata">

**Author:** ![Lukas\_Hejtmanek](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/lukas_hejtmanek/32/18249_2.png) [@Lukas\_Hejtmanek](https://discourse.jupyter.org/u/Lukas_Hejtmanek)\
**Post date:** [April 8, 2025, 9:35pm UTC](https://discourse.jupyter.org/t/next-parameter-lost-after-login-via-oidc-oauth/34042/3 "2025-04-08T21:35:59Z")

</div>

The problem here is, that redirect to OIDC authentication proxy discards all parameters in URL when redirected back to the originator (hub page). So the question basically is, how to solve this problem for Jupyterhub. Working approach is to store URL parameters into session cookie and pick them once returned from the oauth proxy.

Usecase here is to provide a URL with parameters, e.g., notebook name to be opened, like personalised URL for a student homework. Studen opens the link, it redirect him to oauth for credential, redirects back and the original parameters are currently lost.

So is there already any support in the Jupyterhub code, to remember parameters in the session cookie, where to go after login?

---

<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:** [April 9, 2025, 1:27pm UTC](https://discourse.jupyter.org/t/next-parameter-lost-after-login-via-oidc-oauth/34042/4 "2025-04-09T13:27:59Z")

</div>

If you’re using the latest oauthenticator the next URL should be stored in a cookie:

> <https://github.com/jupyterhub/oauthenticator/blob/109018ef6e62bb9eed62f86af4c08929ac37c524/oauthenticator/oauth2.py#L131-L140>

> <https://github.com/jupyterhub/oauthenticator/blob/109018ef6e62bb9eed62f86af4c08929ac37c524/oauthenticator/oauth2.py#L233-L237>
