-
-
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
Sessiontoken renewal #7248
Comments
@mtrezza, I will reference here and close the topic that opens so as not to become a duplicate topic. |
@dblythy According to avoid long life token, there are two main reasons:
|
@dblythy exactly the OAuth 2.0 proposal, as you mentioned:
|
Thanks for the detail in explaining this. I'd figure it would lead to greater discussion if we're all clear on the pros and cons of this implementation. So if I understand correctly: Current:
With Oauth2.0:
If that's the case, I'm in favour of adding the option for using OAuth, where Parse developers can opt in to allowing it in their configuration. Then, I'd expect that:
I'm not overly familiar with OAuth2.0 but as you've explained it, it seems to be a welcome improvement on the current auth system. |
@dblythy a primary outline follows. Please read this introductory document on what is the JWT The idea is not to change the structure of the current Parse Server, but to implement the OAuth 2.0 rules. So, even if the choice is to use "oauth", Parse will continue to work with "sessions", it will only generate accessToken to allow access, as follows. In the verification mechanisms when reading the header "X-Parse-Session-Token" (with "oauth" enabled) the SDK's instead of passing the sessionToken will pass the accessToken.
Important points:
In my case I use Parse Server for iOS, Android and the Web. For the Web (if the request uses the X-Parse-Javascript-Key), I decline to send the refreshToken, due to the weakness in not securely maintaining the refreshToken. In mobile developments, iOS (keychain) I can safely store just like in Android (Keystore) the refreshToken. |
Just to throw this in: a migration scenario would be interesting to consider. It is not unusual that online services require all users to sign-in in again when they make a major shift to a more secure auth mechanism that supersedes a former best practice mechanism. |
keeping "oauth" (Parse Server Options) as default (oauth: false), nothing will change, the same function remains. @mtrezza if I understood correctly, the migration scenario would be how SDK's should respond in the case of authentication by OAuth? |
Yes, I mentioned the migration just to be considered on a high level. I can imagine that there will be developers who are interested in using OAuth2 and would want to migrate. If it's just a switch in the options, then it only requires to read the docs and maybe adapt the app, but if it requires more, then this may be something to think about. |
there will be a change for the SDK's, for the developer, it will only be necessary to set "oauth" = true. I will prepare a scope of the change that should be made for the SDK's. Thanks @mtrezza |
Speaking from the Parse-Swift SDK, the flow mentioned in #7248 (comment) seems straight-forward and can probably be done quickly. @jjunineuro question, you mentioned the client needs to check expiration time. This seems like it “may” be slightly problematic as it’s dependent on a local device clock as oppose to a centralized server clock. Meaning it’s hard to enforce a device stays on the same clock, even if it’s the originating clock. My guess here, if a local clock changes and thinks the |
Hello @cbaker6 , both the creation date and the expiration of the token are sent in timestamp, which I believe the time of the device with the time of the server should not interfere. In the previous scheme I was wrong to put the formatted date, but it will be sent in timestamp. What can be done is as follows, the SDK's will check the expiration time (timestamp) and check if it has already expired, if it is expired, request the renewal of the token, to obtain the new access. Token example:
Return of the login / signup request:
I started the sketch, but it is not yet finished. I still have to elaborate the schema for the SDK´s as @mtrezza asked. |
If the timestamps and determining expiration is solely dependent on the local device, it opens up the attack surface for a malicious user as they can simply manipulate the local wall clock or never ask for a refresh token. If it's using both clocks (local and server), there's no way to guarantee these clocks are in sync, even if you are using a value to represent time like |
The expiration timestamp is sent only to the device to check if the "accessToken" is still valid to find out whether to request the update. |
Firebase, with jwt, does exactly the same: when you login It returns token, refresh and validity. Another mechanism to know if the token Is expired Is ti control the response ( usually a 403 auth error, but it could be the current session token expiration error). |
I see, since the server still validates the time, it addresses the problem I mentioned. This means everything depends on the server (centralized) clock, which is perfectly fine. The device can use its local clock to determine if it needs to request a refresh, but even if its clock is out of sync or has been tampered with, the server will still say it's expired and needs to refresh? |
I've done the following steps
|
@cbaker6, even if the device time is changed, the request will be invalid. For example: Access token expires 2021-03-09 17:40:00, I change the device time to 2021-03-09 17:20:00 and make the request with the token.
What will prevail is the expiration date (timestamp) that is in the valid token. |
@jjunineuro you are right, having an ISO OAuth 2 endpoint for parse server login/signup will be a nice addition ! And also will permit an easier use of parser from other services (like Zapier, Intergromat, etc...) @mtrezza My PR for the auth adapter system could be used but it won't play correctly since Oauth 2 spec need special endpoint and in my refactor all data needed for signup/login should be passed under Here i think it's better to have a dedicated endpoint (following OAuth 2 spec) and new field in user response login/signup as mentioned by @jjunineuro OLD ANSWER
|
@Moumouls for this proposal, also does not use the device time. The intention is to optionally implement the OAuth 2.0 protocol. Nothing will change the current structure of the Parse Server, just increase one more option. I kindly ask you to take a look at the diagram above where I explain in more detail the implementation. As @FunnyDevs explained, Firebase uses the same method. |
Yup, this seems like what I stated here:
|
That's right, sorry, I wanted to try to explain it again. Translation error. :) |
Let me know when you all need help with the client side in Parse-Swift. I should be able to quickly write an implementation that you can test/verify in Swift Playgrounds. If there are ideas you want to bounce off of me on the client side, feel free and I can give input there as well. |
Thanks @cbaker6 |
@jjunineuro sorry for my wrong answer, i missed some points and also the closed issue link about the Oauth 2 proposal as a login mechanism: My reply has been updated: #7248 (comment) |
@Moumouls didn't miss a point. We are here to collaborate together. I'm having a hard time dealing with the return of the Signup method. I added the "handleCreate ()" metoro in UsersRoute.js, but I can't handle the return.
|
Yes @jjunineuro the auth system of Parse server is quite complex, that's why i worked on #7079, Here some example on how to return additional data in UserRouter: https://github.com/parse-community/parse-server/pull/7079/files#diff-f11af7a88828d21067e0ce14792d599fc9bd94a9ad8715299ad514ce48544a71 I think my PR could help you on the server side integration, in my PR i've added And use challenge endpoint example to implement refresh logic :) Note: The OAuth 2 implementation will not conflict with my authData rework normally |
@Moumouls see if you can help me, I need to handle the response from rest.create (), I did it at login and it worked perfectly. But not here :(
|
@Moumouls resolved already. |
Does the parse dashboard show these changes automatically or it must be edited too? |
In the Parse Dashboard, it displays the change. When setting "oauth" to true, the only field that will be saved is "refreshToken" in the "_Session" class. No more data is saved. |
Some suggestions:
|
Good, I will make this change.
I put this parameter as a way to facilitate SDK´s. But I will fix. |
I just edited my previous comment.
I mentioned this because we would not want to increase data traffic for existing deployments that may not even use that feature.
That sounds like default would be oauth, but I understood so far that the default would still be the sessionToken?
|
For those who use for mobile and web, it is a great reinforcement. I will implement it myself and create a PR to meet this parameter in Flutter. Yes the default for authentication validation is OAuth, I am using the sessions to not have to change the entire structure of the Parse Server and not to have to write a session structure again for the OAuth protocol. The way I implemented it, I reduced to a minimum a structural change of the system and continues perfectly to comply with the specifications of OAuth as well as maintaining the characteristics of Parse Server. In the description of the Parse Server Options, I describe that when using OAuth, it is advisable to define that the sessions do not expire due to inactivity, and the expiration period (default 1 year) of 100 years. Let's say we have refreshToken from a session that was invalidated, breaking OAuth's philosophy. |
In the tests I performed, when activating "oauth", and later disallowing it, Parse Server continues to carry out the authentication work successfully. |
That would have been my next question :-) Great! |
The OAuth protocol actually remains using a session, but encapsulates that information within the Json Web Token (JWT) and signs that information. What is made available to the user's device is the JWT. As the Parse Server already has a whole system to work the sessions, it would not be possible for me to create another structure that would have the same result. So I just perfected the return treatment. |
A question, in "../src/Options/Definitions.js", if the parameter "oauth" is different from null (I'll change it to string), can I set the values of "expireInactiveSessions = false" and "sessionLength = 31536000 * 100"? |
|
If the "oauth20" parameter is different from empty, you must define:
|
The logic to set config default values is in
The usual approach would be to set default values for these 2 parameters and let the developer override the defaults if necessary. The defaults should reflect the most likely, most commonly used configuration a development would seek. Then, in the auth logic, the values of these 2 parameters would only be considered if |
An excellent idea, but in "../src/Config.js" I didn't find "securityCheck" |
Sorry, it's actually called |
I just need to correct the commit tests I performed, it is failing in the new functions implemented. I don't really know how to implement the tests. |
Would this work also with multi-device (multiple sessions) users? Let's say user sign in with Apple or Username/Password on two devices and get two sessions. Then he eventually stop using one, where the session should expire and on the other the should be silently able to renew the session. Or on the other hand he should be able to renew tokens on each sessions without affecting other sessions. Any idea when this could be released? Thank you! |
🎉 This change has been released in version 6.1.0-alpha.11 |
🎉 This change has been released in version 6.3.0-beta.1 |
🎉 This change has been released in version 6.3.0-alpha.1 |
🎉 This change has been released in version 6.3.0 |
New Feature / Enhancement Checklist
Current Limitation
Parse hasn't a strategy to renew a session token after it expires: so the user, to authenticate itself, must insert the credential agains. This is a big limitation in mobile applications.
Originally discussed in the community forum.
Feature / Enhancement Description
Add endpoint to renew the session token expire time together with new configuration parameters to define the renewal strategy
The text was updated successfully, but these errors were encountered: