-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(login): add remember me functionality #415
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
Conversation
- replace ngCookies by ngStorage: ngCookies only supports session cookies / ngStorage supports both local and session storage - add remember me checkbox in login.html and login.jade - pass remember me parameter to auth.service in login.controller - replace $cookieStore by $localStorage and $sessionStorage in app.js/coffee - replace $cookieStore by $localStorage and $sessionStorage in auth.service.js/coffee - add an expire parameter to signToken method in the server side auth.service.js Notes: - $sessionStorage is used when « remember me » is not checked - $localStorage is used when « remember me » is checked - with « remember me » checked, the token will expire after 7 days Closes #259 (partly)
- replace angular-cookies by ngStorage
|
One issue I have with local/session storage: when you log in and open a new tab or new window, you're logged out. I don't think thats acceptable behavior. |
I would say, it's a NO GO. ;) |
|
I'm not sure what this feature does exactly. How is
Isn't extending token lifetime enough? IMO:
Here I extended token lifetime to Alternatively, but that's more difficult and I'm not certain if worth doing, with |
|
ngCookie store the token only in a session cookie. That means the token is lost every time the user close his browser. That's because I switch to ngStorage. If you want to keep the token longer, you have to store it in a local cookie (not supported with ngCookie). IMO:
I will work on it and will come back with a new PR. |
|
Regarding 1. I'm not saying we should store it in browser. Browsers already do that, and that's what users are used to, we should only make sure we aren't blocking this default behaviour. I hate websites where it's blocked (except for banks). Also browsers always prompt you whether or not you want those credentials stored. |
|
Maybe we should swap out ngCookie for a more robust cookie library so that we aren't restricted to a session cookie. |
|
Sorry @chester1000, I didn't read your point 1 thoroughly enough. You're right. @DaftMonk, I also found another npm: basil.js and I had in mind to angularize it in a service. |
|
Good news: the token seems to be not shared between taps/windows only with
|
use $cookies instead of $sessionStorage allows to share token betwenn tabs or windows
add ngCookies to karma.conf.js for fixing npm test
|
I replaced $sessionStorage simply by $cookies if |
|
I'm still having this issue with localStorage |
|
For on Chrome, Firefox and Safari, It can't reproduce the issue with localStorage. What is your browser? Here is a browser compatibility list. |
|
Oh, I thought that this issue changes default behaviour to remove token upon exit when How about skipping IMO:
if
In both cases:
|
Totally right. If you develop an app, you should able to say if security is a critical point (like banking web portal). So you could choose between never remember and ever remember until logout. Skipping the checkbox would be the right option.
I don't know if there is something to do about it. Is there a mean to link the token with the browser? I don't think so. IMO I tried to replace but I can't figure out why it isn't working. Must be to tired... Any thought? |
|
There are ways to revoke tokens. We would have to notify server about it upon logout, though. |
|
Why notifying the server? The token is only stored on the client side, isn't it? |
|
Yes, but token revoking must happen on the server side. |
|
I don't understand how you can revoke a token? The verification is only based on the secret and expiration date. The only way I see to revoke token would be to store the revoked token in a database. What is the point to use token if you need to perform a request to a database to check if a token is not revoked? Perhaps, by restraining this request only for specifics restricted endpoints? |
|
As I said:
The easiest to implement, but also a little silly solution would be to attach |
|
You convinced me. But why do mean it is little silly? And btw, any idea why isn't working? I also tried with |
|
I'm not sure if all browsers respect AFAIK you MUST return from this function ex. If that won't work, try putting your code inside: |
|
I think the default functionality should be to keep the token for as long as its valid, and set its expiration to around a month. But as @chester1000 pointed out, we might want a way to invalidate tokens from the server side. This is one way I was thinking of implementing server side logouts for tokens: http://stackoverflow.com/questions/21978658/invalidating-json-web-tokens/24235103#24235103 It wouldn't be stateless, which is one of the advantages of using jwt in the first place, but you really can't get around requiring some state to be stored on the server if you're going to do a server side logout. |
|
@DaftMonk how about multi-device setup? |
|
@chester1000 It would log you out everywhere, which wouldn't be ideal in some cases. That said, with a blacklist of tokens, it could get messy over time if you don't clean up expired tokens. |
As @chester1000 said revoked token could be stored in the |
|
@remicastaing Right, but that still wouldn't be stateless. |
|
No revoking solution will be stateless per se. The best thing that comes to my mind is to create new DB For one-instance setup it would be enough to append in-memory list with each revoke, for multiple-instance setup we can sync it with db each ex. 5 minutes. With this, number of db requests is independent to server load. We obviously store tokens there only until they expire. |
+1
But, we would have a revoked token for each logout and with paranoid users, it would be a lot. To keep the amount of revoked token in db/memory constant, we could set the expiration time of 2 days and provide a new token every day. Then we would have one revoked token per user and all per logout revoked token for the last two days. |
Should I start to strip the I would keep the token revocation for later. |
|
Well, we can implement it with short living tokens, and then add |
|
I made a new PR: #444. |
Notes:
Closes #259 (partly)