Closed acrolink closed 7 years ago
I'll look into this and get back to you as soon as I can.
I think this is probably best handled by using refresh tokens.
I hope to be able to add support for this within the next week or two.
Sorry about the delay.
After looking into this issue a bit more, I think that refresh tokens are probably not the best option, as they are designed for a different type of workflow.
Instead, I think either of the following two options can be used.
This process will be similar to the login process.
When checking if the token is valid, you can perform other checks as well (same IP address, etc.).
You will need to store information about how long the user has stayed logged in because this will no longer be present in the token.
If you have any further questions, please let me know.
I am using 100% VueJS
on the front-end with Phoenix JSON API on the back-end. I think tokens can be extended this way:
Does this sound reasonable? Which validations are reasonable to do on the back-end before issuing a new token, besides IP?
Thank you.
Yes, the outline you provide sounds fine. A couple of comments:
Does the session based mechanism provide any refresh cookie feature?
Don't want to kindle an old issue, but refreshing tokens only using existing access tokens is a security vulnerability as an attacker can compromise an access token and keep renewing it infinitely. The standard flow of how this is accomplished using refresh tokens is, in your end point to get a new access token, you'd pass in the refresh token, existing access token, username and password. Even if one of them fail/aren't available, then you would force the user to re-login. Now, at this time you can do your other checks as well such as IP, User agent, etc. etc.
An added layer of security would also be to keep track of existing logins and probably keep the user informed of it through a separate sessions table or similar (Phauxth already provides create_session
function in SessionController which could be re-used for this).
@dsignr thanks for the input. I will look into how others handle this, and I will probably add something to the wiki about it
@riverrun Hi David, thanks for your reply. I found this super useful resource which explains the spec in full. https://tools.ietf.org/html/rfc6749
It's a bit of a long read, but actually goes into every nitty gritty. I'm trying to implement Phauxth based on that link, I'll see if I can get something working so I can share it or send you a PR.
I assume that the default setting of 4 hours max-age for token validity does not take into consideration if the token is actively being used or if it is idle, i.e. it always expires 4 hours after generation (login). How to make it expire only after 4 hours of being idle (not used)?