# SPA, PWA offline mode, localStorage + rotating tokens?

**URL:** <https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576>\
**Category:** Get Help\
**Tags:** auth0-spa-js, vuejs, pwa, auth0\
**Created:** [July 20, 2020, 7:41am UTC](https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576 "2020-07-20T07:41:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kit.zeller](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kit.zeller/32/13267_2.png) [@kit.zeller](https://community.auth0.com/u/kit.zeller)\
**Post date:** [July 20, 2020, 7:41am UTC](https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576/1 "2020-07-20T07:41:12Z")

</div>

This question is a follow-up on [VUE SPA offline, how to remain authenticated?](http://community.auth0.com/t/vue-spa-offline-how-to-remain-authenticated/46547).

The documentation mentions two things in relation to offline authentication.

1. Using localStorage opens you up to XSS attacks.  
[Auth0 Single Page App SDK Code Grant Flow with PKCE. - Auth0 Docs](https://auth0.com/docs/libraries/auth0-spa-js#change-storage-options)

Ok, I understand this on principle. However, it seems that there are no alternatives when remaining authenticated and offline are required? Also, to make an educated decision on using localStorage, how real/bad is this danger??

1. Rotating tokens have some relation to offline authentication.  
[Auth0 Single Page App SDK Code Grant Flow with PKCE. - Auth0 Docs](https://auth0.com/docs/libraries/auth0-spa-js#use-rotating-refresh-tokens)

Following the paragraph on localStorage is the one on rotating refresh tokens, it mentions:

> “Once configured, the SDK will request the `offline_access` scope during the authorization step.”

I’ve been re-reading the docs on it a few times, but have difficulty to make it click as to what this really does/fixes, and if this is intended as a fix (or even a requirement) for localStorage+offline mode?

While tinkering on my site, I first changed to rotating tokens, and then added localStorage; this combo made it work. I now wonder if I have to move back to non-rotating tokens again?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 20, 2020, 8:48pm UTC](https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576/3 "2020-07-20T20:48:09Z")

</div>

> [@kit.zeller](#):
>
> Ok, I understand this on principle. However, it seems that there are no alternatives when remaining authenticated and offline are required? Also, to make an educated decision on using localStorage, how real/bad is this danger??

Before rotating refresh tokens were implemented we would continue a session (issue new access tokens) by verifying a cookie. This is still an option, but has become less reliable because of ITP implemented in some browsers.

The tokens rotate as an added security feature. All of this is outlined in the docs you have linked. There is plenty of debate out there about how vulnerable modern frameworks are to XSS and how many are automatically protecting against it, but that is a larger question.

The offline\_access scope is a specific request for an edit: ~~access token~~ refresh token. If you want to read about it specifically, you can see the spec here:

> **[Final: OpenID Connect Core 1.0 incorporating errata set 1](https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess)**
>
> OpenID Connect Core 1.0 incorporating errata set 1

---

<div class="post-metadata">

**Author:** ![kit.zeller](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kit.zeller/32/13267_2.png) [@kit.zeller](https://community.auth0.com/u/kit.zeller)\
**Post date:** [July 21, 2020, 7:34am UTC](https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576/4 "2020-07-21T07:34:15Z")

</div>

In regards to #1: Can someone confirm that in order to remain authenticated offline, you need to employ a form of local storage?

> It seems that there are no alternatives when remaining authenticated and offline are required?

---

<div class="post-metadata">

**Author:** ![kit.zeller](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kit.zeller/32/13267_2.png) [@kit.zeller](https://community.auth0.com/u/kit.zeller)\
**Post date:** [July 21, 2020, 7:44am UTC](https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576/5 "2020-07-21T07:44:28Z")

</div>

> [@dan.woda](#):
>
> The tokens rotate as an added security feature. All of this is outlined in the docs you have linked. There is plenty of debate out there about how vulnerable modern frameworks are to XSS and how many are automatically protecting against it, but that is a larger question.
> 
> The offline\_access scope is a specific request for an access token. If you want to read about it specifically, you can see the spec here:
> 
> [Final: OpenID Connect Core 1.0 incorporating errata set 1](https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess)

Can I summarise this in an answer as: **Yes. Rotating refresh tokens improve security when using localStorage and are the preferred choice when remaining authenticated offline is used?**

In addition, for other people stumbling upon this topic who are entirely new to authentication/authorization; I found this useful to start understanding the aformentioned “scopes”:

[https://auth0.com/docs/protocols/oauth2](https://auth0.com/docs/protocols/oauth2)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 22, 2020, 1:33pm UTC](https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576/6 "2020-07-22T13:33:26Z")

</div>

> [@kit.zeller](#):
>
> In regards to #1: Can someone confirm that in order to remain authenticated offline, you need to employ a form of local storage?

I think defining what you mean by _remain authenticated offline_ could be helpful here. In the past, SPAs have used silent auth (with cookies and no localstorage) to get a new access token without user interaction.

> [@kit.zeller](#):
>
> Can I summarise this in an answer as: **Yes. Rotating refresh tokens improve security when using localStorage and are the preferred choice when remaining authenticated offline is used?**

I think that is fair. If cookies are being blocked by ITP then it is the only option we recommend.

> [@kit.zeller](#):
>
> In addition, for other people stumbling upon this topic who are entirely new to authentication/authorization; I found this useful to start understanding the aformentioned “scopes”:
> 
> [OAuth 2.0 Authorization Framework](https://auth0.com/docs/protocols/oauth2)

Thanks for providing this insight.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 6, 2020, 1:33pm UTC](https://community.auth0.com/t/spa-pwa-offline-mode-localstorage-rotating-tokens/46576/7 "2020-08-06T13:33:30Z")

</div>

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