Skip to content

Commit

Permalink
Add Users.verify_email() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatascastro12 committed Aug 22, 2023
1 parent 245de37 commit fffb80f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,16 @@ def test_send_verification_email(
"users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0/send_verification_email"
)
assert response["id"] == "auth_challenge_01E4ZCR3C56J083X43JQXF3JK5"

def test_verify_email(self, capture_and_mock_request, mock_user):
magic_auth_challenge_id = "auth_challenge_123"
code = "code_123"

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

response = self.users.verify_email(
magic_auth_challenge_id=magic_auth_challenge_id, code=code
)

assert url[0].endswith("users/verify_email")
assert response["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
34 changes: 34 additions & 0 deletions workos/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
USER_PASSWORD_RESET_CHALLENGE_PATH = "users/password_reset_challenge"
USER_PASSWORD_RESET_PATH = "users/password_reset"
USER_SEND_VERIFICATION_EMAIL_PATH = "users/{0}/send_verification_email"
USER_VERIFY_EMAIL_PATH = "users/verify_email"

RESPONSE_LIMIT = 10

Expand Down Expand Up @@ -435,3 +436,36 @@ def send_verification_email(
)

return WorkOSMagicAuthChallenge.construct_from_response(response).to_dict()

def verify_email(
self,
magic_auth_challenge_id,
code,
):
"""Verifies user email using one-time code that was sent to the user.
Kwargs:
magic_auth_challenge_id (str): The challenge ID returned from the send verification email endpoint.
code (str): The unique ID of the User whose email address will be verified.
Returns:
dict: User response from WorkOS.
"""

headers = {}

payload = {
"magic_auth_challenge_id": magic_auth_challenge_id,
"code": code,
}

response = self.request_helper.request(
USER_VERIFY_EMAIL_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 fffb80f

Please sign in to comment.