-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it safe to save refresh_token locally? #13
Comments
If you save it in a httpOnly secure cookie it is. Otherwise it'll certainly be vulnerable to XSS attacks. |
I want also to highlight the fact that, as soon as you start to work with a web application that authenticate against a security server using bearer tokens, you must work in SSL mode except if the application is executed inside a safe intranet. Despite the technology used, or the client side framework used, sharing communications using a bearer tokens require SSL, always. |
In this project, the access_token and refresh_token are saved in the localStorage. |
Yes and it shouldn't. That exposes the refresh_token to XSS attacks. |
Then where should I save the tokens, I don't want my users to log in every time they view my site? |
You should save it in a httpOnly secure cookie. A cookie with the httpOnly flag, cannot be retrieved by javascript in browsers supporting the httpOnly flag (most modern) and the secure flag forces the cookie to be sent over SSL (again in browser supporting this flag). You'll need a few changes both server and client-side to make this happen. |
We are implementing open id connect authentication + oauth2 authorization using IdentityServer. I asked them a question about how to be able to set a short access token lifetime but still be able to have a long user session in the browser without refresh tokens. In our project we have a pure angular app with no front server. I was directed to this example: https://github.com/IdentityServer/Thinktecture.IdentityServer3.Samples/tree/master/source/OAuthJS. It fetches a new access token based on a timer using a hidden frame. This way the access token can be short-lived (e.g. 5 minutes) but the user can have a longer browser session that is not linked to the lifetime of the token. We store the access token inside Javascript in order to be able to attach it to the API requests (API is located in a different URL from the authentication server). |
No problems if you use the proxy pattern. Save them into a crypted cookie and the proxy server will decrypt that token sended in a header, then the proxy will use the token to get resources from the api server. Finally it will send it back to the browser |
As angularjs is a client-based application, is it safe to save refresh_token locally?
In this project, the access_token and refresh_token are saved in the localStorage.
The text was updated successfully, but these errors were encountered: