-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Added session length option for session tokens to server configuration #997
Conversation
Current coverage is
|
@Kenishi updated the pull request. |
// Validate session length, default to 1 year if not set | ||
sessionLength = Number(sessionLength) | ||
if(isNaN(sessionLength) || sessionLength <= 0) { | ||
sessionLength = 31536000000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the default value at the top, when we spread the options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add the validation that the sessionLength is valid in Config.validate, and throw an error if the session length is not valid
@Kenishi updated the pull request. |
@@ -36,12 +36,16 @@ export class Config { | |||
this.authDataManager = cacheInfo.authDataManager; | |||
this.customPages = cacheInfo.customPages || {}; | |||
this.mount = mount; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove space
By "each place" do you mean in each location where a session object is created? |
That is exactly what I mean, maybe refactor that code in order to have something centralized and not all over the place, but not refactor by overriding the value before saving |
@Kenishi updated the pull request. |
Just to make sure I understand, changing to something like this would be preferred?
This would be done at 2 locations in RestWrite and 1 location in UsersRouter. Unless what you are suggesting is to have a function somewhere that can be called to get a JS Date object for the expiresAt time? Something like:
If thats the case, any suggestions in what class this should go? Config seems the most straight forward but I'm not sure it makes sense. |
I makes sense to put it in config for many reasons,
|
@Kenishi updated the pull request. |
Let me know if you need me to do anything about the fails. I ran |
@Kenishi updated the pull request. |
1 similar comment
@Kenishi updated the pull request. |
Did I rebase that correctly? |
The only real problem here is that session expiration isn't actually implemented. Are you interested in working on that as well? As for rebasing, there are still 7 commits listed. Ideally there should only be one. What I've been doing to update a single commit during PR development is: git add .
git commit --amend
# ^ by default this opens an editor with a commit message, just save/quit.
git push -f
# ^ force pushes the now amended commit |
I'm not sure I completely follow. Do you mean like having the session deleted from the database after it has expired? I'd be interested in working on this if it isn't very complicated. |
At the moment it's just a date field, no logic changes based on its value. After the expire time, it still works. During the beginning of the request cycle, probably in |
I looked at this the other day. I think I can probably add something to middleware for handling expired sessions. My main question is how should an expired token be handled? Should it just reject the request with an error like |
In general we do our best to match the behaviour of Parse.com. If you have a Parse.com account, try it on an app on Parse.com and then duplicate that behaviour. If you don't, send me a message with your email address and I can create one for you. |
@drew-gross I might have some time to get the middleware stuff in place. I tried following your suggestion and checking how the Parse.com handles an expired session token, but I can't test it because the server won't allow the expiresAt field to be modified. It kicks back an error about expiresAt being read-only (when directly editing in dashboard) or a reserved word (REST API). |
@Kenishi OK, I checked in the source code. The response for an expired session should be the exact same response as for a revoked or invalid session token. |
@Kenishi updated the pull request. |
Okay. I added a check in Auth.getAuthForSessionToken to see if the session has expired. If it has then it throws a |
That error handling looks a little weird but seems to work, and the code is otherwise solid. Merging. |
merging! |
I'm not sure if this is the best way to go about doing this, but it seems like the least painless route.
This allows you to specify a session length in milliseconds for how long session tokens should be good for. If one isn't specified then it falls back to 1 year.
Added some test coverage for the implementation of this on RestWrite. I think there should also ideally be one test in the index.js spec as well, but I'm not sure what the best way of doing that is.