# How to refresh oauth tokens

**URL:** <https://discourse.jupyter.org/t/how-to-refresh-oauth-tokens/4553>\
**Category:** JupyterHub\
**Created:** [May 26, 2020, 9:28am UTC](https://discourse.jupyter.org/t/how-to-refresh-oauth-tokens/4553 "2020-05-26T09:28:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ableuler](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/ableuler/32/2141_2.png) [@ableuler](https://discourse.jupyter.org/u/ableuler)\
**Post date:** [May 26, 2020, 9:28am UTC](https://discourse.jupyter.org/t/how-to-refresh-oauth-tokens/4553/1 "2020-05-26T09:28:31Z")

</div>

Hi all,  
I seem unable to find any documentation on how to use the refresh token issued together with an oauth access token to actually refresh the token. I’d assume that this happens through another POST request to the [token endpoint](https://jupyterhub.readthedocs.io/en/stable/_static/rest-api/index.html#path--oauth2-token), but I don’t know which parameters I have to provide for this to work. Any help or link to an example would be great!

---

<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:** [May 29, 2020, 11:34am UTC](https://discourse.jupyter.org/t/how-to-refresh-oauth-tokens/4553/2 "2020-05-29T11:34:07Z")

</div>

Which Authenticator are you using?

JupyterHub doesn’t issue refresh tokens at this point. Are you perhaps thinking of the OAuth provider used to login to jupyterhub (It’s confusing, but there are usually _two_ OAuth providers involved here - your OAuthenticator that users login with, assuming you are using an OAuth source of users, and JupyterHub itself, which acts as an OAuth provider for notebook servers).

If you are asking about refreshing the token stored in auth\_state, this would be implemented in `Authenticator.refresh_user`, which would need to make the appropriate requests to the OAuth provider.

---

<div class="post-metadata">

**Author:** ![ableuler](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/ableuler/32/2141_2.png) [@ableuler](https://discourse.jupyter.org/u/ableuler)\
**Post date:** [May 29, 2020, 1:46pm UTC](https://discourse.jupyter.org/t/how-to-refresh-oauth-tokens/4553/3 "2020-05-29T13:46:07Z")

</div>

Hi @minrk,  
thanks a lot for your answer. I’m thinking of JupyterHub as an OAuth provider. We are indeed using GitLab for logging into JupyterHub, but that’s not what I was talking about.

I did look into the code in the meantime and I also concluded that refreshing OAuth access tokens is not yet implemented and that the OAuth access tokens **do not** expire. Is this correct?

---

<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:** [June 4, 2020, 10:08am UTC](https://discourse.jupyter.org/t/how-to-refresh-oauth-tokens/4553/4 "2020-06-04T10:08:53Z")

</div>

> [@ableuler](#):
>
> OAuth access tokens is not yet implemented and that the OAuth access tokens **do not** expire. Is this correct?

Correct, but…

JupyterHub has two kinds of tokens: OAuth access tokens, and API tokens. OAuth access tokens _should_ expire by default at one hour (they do not yet, but will in the next release). API tokens support expiry, but do not expire by default. OAuth access tokens are used in the cookies for browser authentication to a given server. API tokens are used for e.g. the server itself to call back to the Hub (for example, completing the oauth flow to issue these oauth tokens).

I do eventually want to merge these and eliminate the distinction. Tasks involved in that:

1. define OAuth scopes for APIs
2. implement scope-based auth for token-authenticated requests
3. implement refresh\_token mechanism and use it in jupyterhub-singleuser
4. enable token expiry by default

---

<div class="post-metadata">

**Author:** ![ableuler](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/ableuler/32/2141_2.png) [@ableuler](https://discourse.jupyter.org/u/ableuler)\
**Post date:** [June 4, 2020, 11:07am UTC](https://discourse.jupyter.org/t/how-to-refresh-oauth-tokens/4553/5 "2020-06-04T11:07:22Z")

</div>

Cool - thanks a lot for the explanation. Looking forward to those improvements!
