Skip to content

Commit

Permalink
Authentication API, Database, Add the organization param to the chang…
Browse files Browse the repository at this point in the history
…e password email method
  • Loading branch information
shchotse committed Oct 23, 2023
1 parent 730b9f5 commit 7fbb7b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion auth0/authentication/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions auth0/test/authentication/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)

0 comments on commit 7fbb7b3

Please sign in to comment.