Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication API, the Database classs, Add the organization param to the change_password method #539

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="[email protected]", 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": "[email protected]",
"connection": "conn",
"organization": "org_id",
},
)