# How to get refresh token like getAccessTokenSilently?

**URL:** <https://community.auth0.com/t/how-to-get-refresh-token-like-getaccesstokensilently/86973>\
**Category:** Get Help\
**Tags:** reactjs, auth0\
**Created:** [July 14, 2022, 11:34am UTC](https://community.auth0.com/t/how-to-get-refresh-token-like-getaccesstokensilently/86973 "2022-07-14T11:34:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![praveenprk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praveenprk/32/38678_2.png) [@praveenprk](https://community.auth0.com/u/praveenprk)\
**Post date:** [July 14, 2022, 11:34am UTC](https://community.auth0.com/t/how-to-get-refresh-token-like-getaccesstokensilently/86973/1 "2022-07-14T11:34:31Z")

</div>

- SDK name: auth0-react
- SDK Version: v1.10.2
- Code Snippets/Error Messages/Supporting Details/Screenshots:

After the user signs in, we can use getAccessTokenSilently and get access token, but how to get refresh token? I can see in the networks tab, there is a page with service worker that gives the response in json that contains refresh\_token along with other things.

Screenshot:

 ![Screenshot 2022-07-14 at 3.59.41 PM](https://global.discourse-cdn.com/auth0/original/3X/8/2/8246464a054623c153cbfb862269a8fb948a9ac3.png)

How can I access this response ? As I am unable to get a hold of this service worker file named token.

---

<div class="post-metadata">

**Author:** ![praveenprk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praveenprk/32/38678_2.png) [@praveenprk](https://community.auth0.com/u/praveenprk)\
**Post date:** [July 14, 2022, 1:21pm UTC](https://community.auth0.com/t/how-to-get-refresh-token-like-getaccesstokensilently/86973/2 "2022-07-14T13:21:54Z")

</div>

So, in order to get the refresh token, you need to first pass `useRefreshToken={true}`. And then, pass `cacheLocation="localstorage"` to the Auth0Provider. This will store the tokens and other response in the localStorage.

And then, you need to use LocalStorageCache class to access the keys and its value.

```auto
    const refresh_token = new LocalStorageCache;
    const key = refresh_token.allKeys().find(key => key.includes('auth0spa'));
    const refresh_token_value = refresh_token.get(key);
    const finalRefreshToken = refresh_token_value?.body?.refresh_token
    localStorage.setItem('refresh_token', finalRefreshToken);

```

Hope it helps!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 14, 2022, 9:03pm UTC](https://community.auth0.com/t/how-to-get-refresh-token-like-getaccesstokensilently/86973/3 "2022-07-14T21:03:49Z")

</div>

Hey there @praveenprk welcome to the community!

Great to know you got this sorted and thanks a bunch for sharing with the community 😄

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 29, 2022, 9:03pm UTC](https://community.auth0.com/t/how-to-get-refresh-token-like-getaccesstokensilently/86973/4 "2022-07-29T21:03:55Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
