diff --git a/tests/test_users.py b/tests/test_users.py index 6ba31309..068283ff 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -208,7 +208,7 @@ def test_authenticate_with_magic_auth( ): code = "test_auth" expires_in = 3600 - magic_auth_challenge_id = "magic_auth_challenge_id" + user = "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" ip_address = "192.0.0.1" @@ -217,7 +217,7 @@ def test_authenticate_with_magic_auth( response = self.users.authenticate_with_magic_auth( code=code, expires_in=expires_in, - magic_auth_challenge_id=magic_auth_challenge_id, + user=user, user_agent=user_agent, ip_address=ip_address, ) @@ -228,7 +228,7 @@ def test_authenticate_with_magic_auth( assert request["json"]["code"] == code assert request["json"]["user_agent"] == user_agent assert request["json"]["expires_in"] == expires_in - assert request["json"]["magic_auth_challenge_id"] == magic_auth_challenge_id + assert request["json"]["user_id"] == user assert request["json"]["ip_address"] == ip_address assert request["json"]["client_id"] == "client_b27needthisforssotemxo" assert request["json"]["client_secret"] == "sk_abdsomecharactersm284" @@ -331,46 +331,38 @@ def test_complete_password_reset(self, capture_and_mock_request, mock_user): assert request["json"]["token"] == token assert request["json"]["new_password"] == new_password - def test_send_verification_email( - self, capture_and_mock_request, mock_magic_auth_challenge_response - ): + def test_send_verification_email(self, capture_and_mock_request, mock_user): user = "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" - url, _ = capture_and_mock_request( - "post", mock_magic_auth_challenge_response, 200 - ) + url, _ = capture_and_mock_request("post", mock_user, 200) response = self.users.send_verification_email(user=user) assert url[0].endswith( "users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0/send_verification_email" ) - assert response["id"] == "auth_challenge_01E4ZCR3C56J083X43JQXF3JK5" + assert response["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" def test_verify_email(self, capture_and_mock_request, mock_user): - magic_auth_challenge_id = "auth_challenge_123" + user = "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" code = "code_123" - url, _ = capture_and_mock_request("post", mock_user, 200) + url, request = capture_and_mock_request("post", mock_user, 200) - response = self.users.verify_email( - magic_auth_challenge_id=magic_auth_challenge_id, code=code - ) + response = self.users.verify_email(user=user, code=code) assert url[0].endswith("users/verify_email") + assert request["json"]["user_id"] == user + assert request["json"]["code"] == code assert response["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" - def test_send_magic_auth_code( - self, capture_and_mock_request, mock_magic_auth_challenge_response - ): + def test_send_magic_auth_code(self, capture_and_mock_request, mock_user): email = "marcelina@foo-corp.com" - url, request = capture_and_mock_request( - "post", mock_magic_auth_challenge_response, 200 - ) + url, request = capture_and_mock_request("post", mock_user, 200) response = self.users.send_magic_auth_code(email=email) assert url[0].endswith("users/magic_auth/send") assert request["json"]["email_address"] == email - assert response["id"] == "auth_challenge_01E4ZCR3C56J083X43JQXF3JK5" + assert response["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" diff --git a/workos/resources/magic_auth_challenge_response.py b/workos/resources/magic_auth_challenge_response.py deleted file mode 100644 index ded41490..00000000 --- a/workos/resources/magic_auth_challenge_response.py +++ /dev/null @@ -1,13 +0,0 @@ -from workos.resources.base import WorkOSBaseResource - - -class WorkOSMagicAuthChallenge(WorkOSBaseResource): - """Representation of a MagicAuthChallenge identifier as returned by WorkOS through User Management features. - - Attributes: - OBJECT_FIELDS (list): List of fields a WorkOSMagicAuthChallenge comprises. - """ - - OBJECT_FIELDS = [ - "id", - ] diff --git a/workos/users.py b/workos/users.py index 9b9aaad9..5d4aa216 100644 --- a/workos/users.py +++ b/workos/users.py @@ -1,6 +1,5 @@ import workos from workos.resources.authentication_response import WorkOSAuthenticationResponse -from workos.resources.magic_auth_challenge_response import WorkOSMagicAuthChallenge from workos.resources.password_challenge_response import WorkOSPasswordChallengeResponse from workos.resources.list import WorkOSListResource from workos.resources.users import ( @@ -198,7 +197,7 @@ def remove_user_from_organization(self, user, organization): def authenticate_with_magic_auth( self, code, - magic_auth_challenge_id, + user, expires_in=None, ip_address=None, user_agent=None, @@ -207,7 +206,7 @@ def authenticate_with_magic_auth( Kwargs: code (str): The one-time code that was emailed to the user. - magic_auth_challenge_id (str): The challenge ID returned from when the one-time code was sent to the user. + user (str): The unique ID of the User who will be authenticated. expires_in (int): The length of the session in minutes. Defaults to 1 day, 1440. (Optional) ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional) user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional) @@ -224,7 +223,7 @@ def authenticate_with_magic_auth( "client_id": workos.client_id, "client_secret": workos.api_key, "code": code, - "magic_auth_challenge_id": magic_auth_challenge_id, + "user_id": user, "grant_type": "urn:workos:oauth:grant-type:magic-auth:code", } @@ -436,19 +435,19 @@ def send_verification_email( token=workos.api_key, ) - return WorkOSMagicAuthChallenge.construct_from_response(response).to_dict() + return WorkOSUser.construct_from_response(response).to_dict() def verify_email( self, - magic_auth_challenge_id, + user, 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. + user (str): The unique ID of the User whose email address will be verified. - code (str): The unique ID of the User whose email address will be verified. + code (str): The one-time code emailed to the user. Returns: dict: User response from WorkOS. @@ -457,7 +456,7 @@ def verify_email( headers = {} payload = { - "magic_auth_challenge_id": magic_auth_challenge_id, + "user_id": user, "code": code, } @@ -498,4 +497,4 @@ def send_magic_auth_code( token=workos.api_key, ) - return WorkOSMagicAuthChallenge.construct_from_response(response).to_dict() + return WorkOSUser.construct_from_response(response).to_dict()