-
Notifications
You must be signed in to change notification settings - Fork 133
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
Invalidate tokens on password change #1783
Conversation
6c763d1
to
32820c1
Compare
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.
lgtm!
32820c1
to
fcaf348
Compare
metadata = user_profile.metadata or {} | ||
metadata['last_password_edit'] = timezone.now().isoformat() | ||
user_profile.user.set_password(new_password) | ||
user_profile.metadata = metadata | ||
user_profile.user.save() | ||
user_profile.save() | ||
data.update(invalidate_and_regen_tokens( | ||
user=user_profile.user)) |
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.
Do we need to return the access and temp token at this point? Could on the UI side simply make the request to the API/user endpoint to retrieve the new information from there as it already does on login?
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.
The tokens that are in UI will already be invalidated so I don't think they can be used to make a request to the user endpoint unless the user logs out, no?
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.
Yes, not necessarily logging out but would need to log in with the new credentials. Will we be terminating the existing session and creating a new one? Essentially as you say, log out and log in a fresh?
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.
No much particular objection but simply wondering.
Should we update the documentation at https://api.ona.io/static/docs/profiles.html#change-authenticated-users-password to reflect that we also return the access and temp tokens?
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.
We don't necessarily have to return the access and temp token at this point, returning them just makes it easier for the API consumer to continue making requesting (Just removes the added step of requesting for a new access token).
UI's will have to change / modify their stored token values. They can decide to terminate a session or just update it's values.
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.
Yes, we should update the documentation. Thank you for bringing that up, let me make that change.
b1096ec
to
afcd54a
Compare
afcd54a
to
89a2045
Compare
@DavisRayM The API token is only updated when a user changes their password from the **Settings ** page. Changing passwords from the |
89a2045
to
f419918
Compare
Thank you for noting this @faith-mutua. The latest commits should handle this now. |
d5cc570
to
78245d2
Compare
@DavisRayM The API token is now being invalidated when a user changes their password via The |
@@ -142,6 +144,29 @@ def change_password_attempts(request): | |||
return 1 | |||
|
|||
|
|||
def invalidate_and_regen_tokens(user): |
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.
Can we have this util function in onadata.libs.authentication
module rather than a view set? Especially since it is also used by the CustomPasswordResetTokenGenerator
class. I think it clutters the viewset.
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.
Yes, I'll make that change.
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.
Changed in the latest commits.
78245d2
to
d09ea1d
Compare
- Invalidate a users api and temporary token when they're password changes either through the password reset email or through an authenticated session. - Modify test to verify that the api and temporary tokens are renewed
Include information about information returned when an authenticated user changes their password
d09ea1d
to
9441a45
Compare
Changes / Features
changes.
Steps taken to verify this change does what is intended
Pending:
Side effects of implementing this change
Closes #1782