Skip to content

Commit

Permalink
Authentication API, the Database classs, Add the organization param t…
Browse files Browse the repository at this point in the history
…o the change_password method (#539)

### Changes

Authentication API, the Database class, added the `organization` param
to the `change_password` method.

### References

https://auth0.com/docs/api/authentication#change-password

### Testing

- [x] This change adds unit test coverage

### Checklist

- [x] I have read the [Auth0 general contribution
guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
- [x] I have read the [Auth0 Code of
Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
- [x] All existing and new tests complete without errors
  • Loading branch information
adamjmcgrath authored Oct 26, 2023
2 parents 89343d9 + 4b40a0c commit 1588c9f
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 1588c9f

Please sign in to comment.