Skip to content

Commit

Permalink
Add Users.complete_password_reset() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatascastro12 committed Aug 22, 2023
1 parent e393e8b commit 30f99f9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,19 @@ def test_create_password_challenge(
assert response["token"] == "token_123"
assert request["json"]["email"] == email
assert request["json"]["password_reset_url"] == password_reset_url

def test_complete_password_reset(self, capture_and_mock_request, mock_user):
token = "token123"
new_password = "pass123"

url, request = capture_and_mock_request("post", mock_user, 200)

response = self.users.complete_password_reset(
token=token,
new_password=new_password,
)

assert url[0].endswith("users/password_reset")
assert response["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
assert request["json"]["token"] == token
assert request["json"]["new_password"] == new_password
33 changes: 33 additions & 0 deletions workos/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
USER_ORGANIZATION_PATH = "users/{0}/organization/{1}"
USER_SESSION_TOKEN_PATH = "users/session/token"
USER_PASSWORD_RESET_CHALLENGE_PATH = "users/password_reset_challenge"
USER_PASSWORD_RESET_PATH = "users/password_reset"

RESPONSE_LIMIT = 10

Expand Down Expand Up @@ -376,3 +377,35 @@ def create_password_reset_challenge(
return WorkOSPasswordChallengeResponse.construct_from_response(
response
).to_dict()

def complete_password_reset(
self,
token,
new_password,
):
"""Resets user password using token that was sent to the user.
Kwargs:
token (str): The reset token emailed to the user.
new_password (str): The new password to be set for the user.
Returns:
dict: User response from WorkOS.
"""

headers = {}

payload = {
"token": token,
"new_password": new_password,
}

response = self.request_helper.request(
USER_PASSWORD_RESET_PATH,
method=REQUEST_METHOD_POST,
headers=headers,
params=payload,
token=workos.api_key,
)

return WorkOSUser.construct_from_response(response).to_dict()

0 comments on commit 30f99f9

Please sign in to comment.