From 7fbb7b3b661cec5be9dc0d2612b26373ec0b75a6 Mon Sep 17 00:00:00 2001 From: Igor Topal Date: Mon, 23 Oct 2023 19:47:38 +0300 Subject: [PATCH] Authentication API, Database, Add the organization param to the change password email method --- auth0/authentication/database.py | 10 +++++++++- auth0/test/authentication/test_database.py | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/auth0/authentication/database.py b/auth0/authentication/database.py index 9bfd6144..17f6322b 100644 --- a/auth0/authentication/database.py +++ b/auth0/authentication/database.py @@ -79,19 +79,27 @@ def signup( return data def change_password( - self, email: str, connection: str, password: str | None = None + self, + email: str, + connection: str, + password: str | None = None, + organization: str | None = None, ) -> str: """Asks to change a password for a given user. email (str): The user's email address. connection (str): The name of the database connection where this user should be created. + + organization (str, optional): The id of the Organization associated with the user. """ body = { "client_id": self.client_id, "email": email, "connection": connection, } + if organization: + body["organization"] = organization data: str = self.post( f"{self.protocol}://{self.domain}/dbconnections/change_password", diff --git a/auth0/test/authentication/test_database.py b/auth0/test/authentication/test_database.py index b7f1d984..1572e1ae 100644 --- a/auth0/test/authentication/test_database.py +++ b/auth0/test/authentication/test_database.py @@ -78,3 +78,25 @@ def test_change_password(self, mock_post): "connection": "conn", }, ) + + @mock.patch("auth0.rest.RestClient.post") + def test_change_password_with_organization_param(self, mock_post): + d = Database("my.domain.com", "cid") + + # ignores the password argument + d.change_password( + email="a@b.com", password="pswd", connection="conn", organization="org_id" + ) + + args, kwargs = mock_post.call_args + + self.assertEqual(args[0], "https://my.domain.com/dbconnections/change_password") + self.assertEqual( + kwargs["data"], + { + "client_id": "cid", + "email": "a@b.com", + "connection": "conn", + "organization": "org_id", + }, + )