Persisting a refresh_token on a SPA
Hi,
I recently came across an article regarding JS Apps with OAuth. It points out how one should not persist the refresh_token on the client side. It goes on further and describe using a proxy api to issue cookies to store the client_id/client_secret and and requested refresh_token among others.
My project uses a Resource Owner Flow, with an API resource and SPA front end. I'm currently storing the refresh_token in localStorage, which seem to be a huge security flaw. Also have https and cors setup to only allow origin from the SPA.
Also, my IdentityServer client is setup for AllowedCorsOrigins to only point to the SPA.
My question is, is this a security hole, and if yes how do I persist the refresh_token in another way? I mean if you can get a hold of the users localStorage they can just use that refresh_token to get new access_tokens, thats only if you could somehow fake the origin.
Thanks for your time.
SPAs should not be obtaining refresh tokens. The implicit flow is designed for SPAs.
Thanks for your reply, however in my case the implicit flow (redirects) would be bad user experience design and also not possible for my use case. The system is running in a trusted environment, meaning I own the Identity Server, API, and SPA, and there will be no other clients besides the ones specified here.
Is it possible to use the resource owner flow with SPA's and also have it secure?
It seems I have three options:
- Long-lived access tokens (and remove refresh_token).
- Proxy in between SPA and API/IdentityServer then use cookies, however I'm not 100% how to do this.
- Go with implicit flow, but design the identity server pages to look the same as the SPA. This seems like the worst option, since there's a mobile app in the works that will require a different look and feel. Meaning multiple views for identity server depending on client. Not to mention, bad user experience (redirects) since the user will never know about identity server and it doesn't suite the specs of the project.
For 3rd party logins (google, twitter etc) its understandable to have redirects because you are integrating with another application, but it doesn't make sense jumping the user around on my application as I'm not really integrating with anything external.
Thanks for the advice.
I'd go for long lived access tokens. Have you considered reference tokens? This gives you similar security characteristics to refresh tokens.
design the identity server pages to look the same as the SPA. This seems like the worst option, since there's a mobile app in the works that will require a different look and feel. Meaning multiple views for identity server depending on client.
I always dislike this approach since it's disingenuous to the user. The user is logging into the token service, not just the app. That's sort of the whole point of SSO. For example, I login to google, not just maps, docs, or gmail.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.