diff --git a/src/workos/user_management/_resource.py b/src/workos/user_management/_resource.py index 0d8fbf3f..85d2600f 100644 --- a/src/workos/user_management/_resource.py +++ b/src/workos/user_management/_resource.py @@ -157,6 +157,9 @@ def authenticate_with_password( email: str, password: str, invitation_token: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with password.""" @@ -171,6 +174,12 @@ def authenticate_with_password( body["client_secret"] = self._client._api_key if invitation_token is not None: body["invitation_token"] = invitation_token + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -183,19 +192,27 @@ def authenticate_with_password( def authenticate_with_code( self, *, - code: Optional[str] = None, + code: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with code.""" body: Dict[str, Any] = { "grant_type": "authorization_code", + "code": code, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -210,6 +227,9 @@ def authenticate_with_refresh_token( *, refresh_token: str, organization_id: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with refresh token.""" @@ -223,6 +243,12 @@ def authenticate_with_refresh_token( body["client_secret"] = self._client._api_key if organization_id is not None: body["organization_id"] = organization_id + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -235,25 +261,32 @@ def authenticate_with_refresh_token( def authenticate_with_magic_auth( self, *, - code: Optional[str] = None, - email: Optional[str] = None, + code: str, + email: str, invitation_token: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with magic auth.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:magic-auth:code", + "code": code, + "email": email, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code - if email is not None: - body["email"] = email if invitation_token is not None: body["invitation_token"] = invitation_token + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -266,22 +299,30 @@ def authenticate_with_magic_auth( def authenticate_with_email_verification( self, *, - code: Optional[str] = None, + code: str, pending_authentication_token: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with email verification.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:email-verification:code", + "code": code, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code if pending_authentication_token is not None: body["pending_authentication_token"] = pending_authentication_token + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -294,25 +335,31 @@ def authenticate_with_email_verification( def authenticate_with_totp( self, *, - code: Optional[str] = None, - pending_authentication_token: Optional[str] = None, - authentication_challenge_id: Optional[str] = None, + code: str, + pending_authentication_token: str, + authentication_challenge_id: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with totp.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:mfa-totp", + "code": code, + "pending_authentication_token": pending_authentication_token, + "authentication_challenge_id": authentication_challenge_id, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code - if pending_authentication_token is not None: - body["pending_authentication_token"] = pending_authentication_token - if authentication_challenge_id is not None: - body["authentication_challenge_id"] = authentication_challenge_id + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -325,22 +372,29 @@ def authenticate_with_totp( def authenticate_with_organization_selection( self, *, - pending_authentication_token: Optional[str] = None, - organization_id: Optional[str] = None, + pending_authentication_token: str, + organization_id: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with organization selection.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:organization-selection", + "pending_authentication_token": pending_authentication_token, + "organization_id": organization_id, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if pending_authentication_token is not None: - body["pending_authentication_token"] = pending_authentication_token - if organization_id is not None: - body["organization_id"] = organization_id + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -353,17 +407,25 @@ def authenticate_with_organization_selection( def authenticate_with_device_code( self, *, - device_code: Optional[str] = None, + device_code: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with device code.""" body: Dict[str, Any] = { "grant_type": "urn:ietf:params:oauth:grant-type:device_code", + "device_code": device_code, } if self._client.client_id is not None: body["client_id"] = self._client.client_id - if device_code is not None: - body["device_code"] = device_code + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return self._client.request( method="POST", @@ -2259,6 +2321,9 @@ async def authenticate_with_password( email: str, password: str, invitation_token: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with password.""" @@ -2273,6 +2338,12 @@ async def authenticate_with_password( body["client_secret"] = self._client._api_key if invitation_token is not None: body["invitation_token"] = invitation_token + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", @@ -2285,19 +2356,27 @@ async def authenticate_with_password( async def authenticate_with_code( self, *, - code: Optional[str] = None, + code: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with code.""" body: Dict[str, Any] = { "grant_type": "authorization_code", + "code": code, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", @@ -2312,6 +2391,9 @@ async def authenticate_with_refresh_token( *, refresh_token: str, organization_id: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with refresh token.""" @@ -2325,6 +2407,12 @@ async def authenticate_with_refresh_token( body["client_secret"] = self._client._api_key if organization_id is not None: body["organization_id"] = organization_id + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", @@ -2337,25 +2425,32 @@ async def authenticate_with_refresh_token( async def authenticate_with_magic_auth( self, *, - code: Optional[str] = None, - email: Optional[str] = None, + code: str, + email: str, invitation_token: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with magic auth.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:magic-auth:code", + "code": code, + "email": email, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code - if email is not None: - body["email"] = email if invitation_token is not None: body["invitation_token"] = invitation_token + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", @@ -2368,22 +2463,30 @@ async def authenticate_with_magic_auth( async def authenticate_with_email_verification( self, *, - code: Optional[str] = None, + code: str, pending_authentication_token: Optional[str] = None, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with email verification.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:email-verification:code", + "code": code, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code if pending_authentication_token is not None: body["pending_authentication_token"] = pending_authentication_token + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", @@ -2396,25 +2499,31 @@ async def authenticate_with_email_verification( async def authenticate_with_totp( self, *, - code: Optional[str] = None, - pending_authentication_token: Optional[str] = None, - authentication_challenge_id: Optional[str] = None, + code: str, + pending_authentication_token: str, + authentication_challenge_id: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with totp.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:mfa-totp", + "code": code, + "pending_authentication_token": pending_authentication_token, + "authentication_challenge_id": authentication_challenge_id, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if code is not None: - body["code"] = code - if pending_authentication_token is not None: - body["pending_authentication_token"] = pending_authentication_token - if authentication_challenge_id is not None: - body["authentication_challenge_id"] = authentication_challenge_id + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", @@ -2427,22 +2536,29 @@ async def authenticate_with_totp( async def authenticate_with_organization_selection( self, *, - pending_authentication_token: Optional[str] = None, - organization_id: Optional[str] = None, + pending_authentication_token: str, + organization_id: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with organization selection.""" body: Dict[str, Any] = { "grant_type": "urn:workos:oauth:grant-type:organization-selection", + "pending_authentication_token": pending_authentication_token, + "organization_id": organization_id, } if self._client.client_id is not None: body["client_id"] = self._client.client_id if self._client._api_key is not None: body["client_secret"] = self._client._api_key - if pending_authentication_token is not None: - body["pending_authentication_token"] = pending_authentication_token - if organization_id is not None: - body["organization_id"] = organization_id + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", @@ -2455,17 +2571,25 @@ async def authenticate_with_organization_selection( async def authenticate_with_device_code( self, *, - device_code: Optional[str] = None, + device_code: str, + ip_address: Optional[str] = None, + device_id: Optional[str] = None, + user_agent: Optional[str] = None, request_options: Optional[RequestOptions] = None, ) -> AuthenticateResponse: """Authenticate with device code.""" body: Dict[str, Any] = { "grant_type": "urn:ietf:params:oauth:grant-type:device_code", + "device_code": device_code, } if self._client.client_id is not None: body["client_id"] = self._client.client_id - if device_code is not None: - body["device_code"] = device_code + if ip_address is not None: + body["ip_address"] = ip_address + if device_id is not None: + body["device_id"] = device_id + if user_agent is not None: + body["user_agent"] = user_agent return await self._client.request( method="POST", diff --git a/tests/test_user_management.py b/tests/test_user_management.py index 8647350e..723f0c82 100644 --- a/tests/test_user_management.py +++ b/tests/test_user_management.py @@ -699,7 +699,7 @@ def test_authenticate_with_password(self, workos, httpx_mock): def test_authenticate_with_code(self, workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = workos.user_management.authenticate_with_code() + result = workos.user_management.authenticate_with_code(code="test_value") assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -719,7 +719,9 @@ def test_authenticate_with_refresh_token(self, workos, httpx_mock): def test_authenticate_with_magic_auth(self, workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = workos.user_management.authenticate_with_magic_auth() + result = workos.user_management.authenticate_with_magic_auth( + code="test_value", email="test_value" + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -728,7 +730,9 @@ def test_authenticate_with_magic_auth(self, workos, httpx_mock): def test_authenticate_with_email_verification(self, workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = workos.user_management.authenticate_with_email_verification() + result = workos.user_management.authenticate_with_email_verification( + code="test_value" + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -739,7 +743,11 @@ def test_authenticate_with_email_verification(self, workos, httpx_mock): def test_authenticate_with_totp(self, workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = workos.user_management.authenticate_with_totp() + result = workos.user_management.authenticate_with_totp( + code="test_value", + pending_authentication_token="test_value", + authentication_challenge_id="test_value", + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -748,7 +756,9 @@ def test_authenticate_with_totp(self, workos, httpx_mock): def test_authenticate_with_organization_selection(self, workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = workos.user_management.authenticate_with_organization_selection() + result = workos.user_management.authenticate_with_organization_selection( + pending_authentication_token="test_value", organization_id="test_value" + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -759,7 +769,9 @@ def test_authenticate_with_organization_selection(self, workos, httpx_mock): def test_authenticate_with_device_code(self, workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = workos.user_management.authenticate_with_device_code() + result = workos.user_management.authenticate_with_device_code( + device_code="test_value" + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -1493,7 +1505,9 @@ async def test_authenticate_with_password(self, async_workos, httpx_mock): @pytest.mark.asyncio async def test_authenticate_with_code(self, async_workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = await async_workos.user_management.authenticate_with_code() + result = await async_workos.user_management.authenticate_with_code( + code="test_value" + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -1515,7 +1529,9 @@ async def test_authenticate_with_refresh_token(self, async_workos, httpx_mock): @pytest.mark.asyncio async def test_authenticate_with_magic_auth(self, async_workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = await async_workos.user_management.authenticate_with_magic_auth() + result = await async_workos.user_management.authenticate_with_magic_auth( + code="test_value", email="test_value" + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -1526,7 +1542,9 @@ async def test_authenticate_with_magic_auth(self, async_workos, httpx_mock): async def test_authenticate_with_email_verification(self, async_workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) result = ( - await async_workos.user_management.authenticate_with_email_verification() + await async_workos.user_management.authenticate_with_email_verification( + code="test_value" + ) ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() @@ -1539,7 +1557,11 @@ async def test_authenticate_with_email_verification(self, async_workos, httpx_mo @pytest.mark.asyncio async def test_authenticate_with_totp(self, async_workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = await async_workos.user_management.authenticate_with_totp() + result = await async_workos.user_management.authenticate_with_totp( + code="test_value", + pending_authentication_token="test_value", + authentication_challenge_id="test_value", + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -1551,7 +1573,11 @@ async def test_authenticate_with_organization_selection( self, async_workos, httpx_mock ): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = await async_workos.user_management.authenticate_with_organization_selection() + result = ( + await async_workos.user_management.authenticate_with_organization_selection( + pending_authentication_token="test_value", organization_id="test_value" + ) + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST" @@ -1563,7 +1589,9 @@ async def test_authenticate_with_organization_selection( @pytest.mark.asyncio async def test_authenticate_with_device_code(self, async_workos, httpx_mock): httpx_mock.add_response(json=load_fixture("authenticate_response.json")) - result = await async_workos.user_management.authenticate_with_device_code() + result = await async_workos.user_management.authenticate_with_device_code( + device_code="test_value" + ) assert isinstance(result, AuthenticateResponse) request = httpx_mock.get_request() assert request.method == "POST"