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

Add password expiration flag #361

Merged
merged 9 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,12 @@ users_history_resp = descope_client.mgmt.user.history(["user-id-1", "user-id-2"]
#### Set or Expire User Password

You can set or expire a user's password.
Note: When setting a password, it will automatically be set as expired.
Note: When setting a password, it will automatically be set as expired unless persistPassword flag will be set to True,
The user will not be able log-in using an expired password, and will be required replace it on next login.

```Python
// Set a user's password
descope_client.mgmt.user.setPassword('<login-id>', '<some-password>');
descope_client.mgmt.user.set_password('<login-id>', '<some-password>', '<persist-password-flag>');

// Or alternatively, expire a user password
descope_client.mgmt.user.expirePassword('<login-id>');
Expand Down
10 changes: 8 additions & 2 deletions descope/management/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,23 +1171,29 @@ def set_password(
self,
login_id: str,
password: str,
persist_password: Optional[bool] = False,
) -> None:
"""
Set the password for the given login ID.
Note: The password will automatically be set as expired.
Note: The password will automatically be set as expired unless the persist_password flag will be set to True,
The user will not be able to log-in with this password, and will be required to replace it on next login.
See also: expire_password

Args:
login_id (str): The login ID of the user to set the password to.
password (str): The new password to set to the user.
persist_password (bool): Keep the password persist so it will not be expired on next log-in

Raise:
AuthException: raised if the operation fails
"""
self._auth.do_post(
MgmtV1.user_set_password_path,
{"loginId": login_id, "password": password},
{
"loginId": login_id,
"password": password,
"persistPassword": persist_password,
},
pswd=self._auth.management_key,
)
return
Expand Down
24 changes: 24 additions & 0 deletions tests/management/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,30 @@ def test_user_set_password(self):
json={
"loginId": "login-id",
"password": "some-password",
"persistPassword": False,
},
allow_redirects=False,
verify=True,
timeout=DEFAULT_TIMEOUT_SECONDS,
)

# Test with persist password
with patch("requests.post") as mock_post:
network_resp = mock.Mock()
network_resp.ok = True
mock_post.return_value = network_resp
self.client.mgmt.user.set_password("login-id", "some-password", True)
mock_post.assert_called_with(
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_set_password_path}",
headers={
**common.default_headers,
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
},
params=None,
json={
"loginId": "login-id",
"password": "some-password",
"persistPassword": True,
},
allow_redirects=False,
verify=True,
Expand Down
Loading