-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add patch users * readme * format * fix typing
- Loading branch information
Showing
5 changed files
with
244 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,11 +67,11 @@ These sections show how to use the SDK to perform permission and user management | |
8. [Manage Flows](#manage-flows-and-theme) | ||
9. [Manage JWTs](#manage-jwts) | ||
10. [Impersonate](#impersonate) | ||
12. [Embedded links](#embedded-links) | ||
13. [Audit](#audit) | ||
14. [Manage ReBAC Authz](#manage-rebac-authz) | ||
15. [Manage Project](#manage-project) | ||
16. [Manage SSO Applications](#manage-sso-applications) | ||
11. [Embedded links](#embedded-links) | ||
12. [Audit](#audit) | ||
13. [Manage ReBAC Authz](#manage-rebac-authz) | ||
14. [Manage Project](#manage-project) | ||
15. [Manage SSO Applications](#manage-sso-applications) | ||
|
||
If you wish to run any of our code samples and play with them, check out our [Code Examples](#code-examples) section. | ||
|
||
|
@@ -472,6 +472,7 @@ descope_client.logout_all(refresh_token) | |
``` | ||
|
||
### History | ||
|
||
You can get the current session user history. | ||
The request requires a valid refresh token. | ||
|
||
|
@@ -545,7 +546,7 @@ tenants = tenants_resp["tenants"] | |
|
||
### Manage Users | ||
|
||
You can create, update, delete or load users, as well as setting new password, expire password and search according to filters: | ||
You can create, update, patch, delete or load users, as well as setting new password, expire password and search according to filters: | ||
|
||
```Python | ||
# A user must have a login ID, other fields are optional. | ||
|
@@ -604,6 +605,13 @@ descope_client.mgmt.user.update( | |
sso_app_ids=["appId1"], | ||
) | ||
|
||
# Patch will override only the set fields in the user | ||
descope_client.mgmt.user.patch( | ||
login_id="[email protected]", | ||
email="[email protected]", | ||
display_name="Desmond Copeland", | ||
) | ||
|
||
# Update explicit data for a user rather than overriding all fields | ||
descope_client.mgmt.user.update_login_id( | ||
login_id="[email protected]", | ||
|
@@ -732,6 +740,7 @@ descope_client.mgmt.access_key.delete("key-id") | |
``` | ||
|
||
Exchange the access key and provide optional access key login options: | ||
|
||
```python | ||
loc = AccessKeyLoginOptions(custom_claims={"k1": "v1"}) | ||
jwt_response = descope_client.exchange_access_key( | ||
|
@@ -1290,7 +1299,7 @@ descope_client.mgmt.project.import_project(export) | |
|
||
You can create, update, delete or load sso applications: | ||
|
||
```Python | ||
```python | ||
# Create OIDC SSO application | ||
descope_client.mgmt.sso_application.create_oidc_application( | ||
name="My First sso app", | ||
|
@@ -1338,6 +1347,7 @@ apps_resp = descope_client.mgmt.sso_application.load_all() | |
apps = apps_resp["apps"] | ||
for app in apps: | ||
# Do something | ||
``` | ||
|
||
### Utils for your end to end (e2e) tests and integration tests | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,6 +513,100 @@ def test_update(self): | |
timeout=DEFAULT_TIMEOUT_SECONDS, | ||
) | ||
|
||
def test_patch(self): | ||
# Test failed flows | ||
with patch("requests.patch") as mock_patch: | ||
mock_patch.return_value.ok = False | ||
self.assertRaises( | ||
AuthException, | ||
self.client.mgmt.user.patch, | ||
"valid-id", | ||
"[email protected]", | ||
) | ||
|
||
# Test success flow with some params set | ||
with patch("requests.patch") as mock_patch: | ||
mock_patch.return_value.ok = True | ||
self.assertIsNone( | ||
self.client.mgmt.user.patch( | ||
"id", | ||
display_name="new-name", | ||
email=None, | ||
phone=None, | ||
given_name=None, | ||
role_names=["domain.com"], | ||
user_tenants=None, | ||
picture="https://test.com", | ||
custom_attributes={"ak": "av"}, | ||
sso_app_ids=["app1", "app2"], | ||
) | ||
) | ||
mock_patch.assert_called_with( | ||
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_patch_path}", | ||
headers={ | ||
**common.default_headers, | ||
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}", | ||
}, | ||
params=None, | ||
json={ | ||
"loginId": "id", | ||
"displayName": "new-name", | ||
"roleNames": ["domain.com"], | ||
"picture": "https://test.com", | ||
"customAttributes": {"ak": "av"}, | ||
"ssoAppIds": ["app1", "app2"], | ||
}, | ||
allow_redirects=False, | ||
verify=True, | ||
timeout=DEFAULT_TIMEOUT_SECONDS, | ||
) | ||
# Test success flow with other params | ||
with patch("requests.patch") as mock_patch: | ||
mock_patch.return_value.ok = True | ||
self.assertIsNone( | ||
self.client.mgmt.user.patch( | ||
"id", | ||
email="[email protected]", | ||
phone="+123456789", | ||
given_name="given", | ||
middle_name="middle", | ||
family_name="family", | ||
role_names=None, | ||
user_tenants=[ | ||
AssociatedTenant("tenant1"), | ||
AssociatedTenant("tenant2", ["role1", "role2"]), | ||
], | ||
custom_attributes=None, | ||
verified_email=True, | ||
verified_phone=False, | ||
) | ||
) | ||
mock_patch.assert_called_with( | ||
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_patch_path}", | ||
headers={ | ||
**common.default_headers, | ||
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}", | ||
}, | ||
params=None, | ||
json={ | ||
"loginId": "id", | ||
"email": "[email protected]", | ||
"phone": "+123456789", | ||
"givenName": "given", | ||
"middleName": "middle", | ||
"familyName": "family", | ||
"verifiedEmail": True, | ||
"verifiedPhone": False, | ||
"userTenants": [ | ||
{"tenantId": "tenant1", "roleNames": []}, | ||
{"tenantId": "tenant2", "roleNames": ["role1", "role2"]}, | ||
], | ||
}, | ||
allow_redirects=False, | ||
verify=True, | ||
timeout=DEFAULT_TIMEOUT_SECONDS, | ||
) | ||
|
||
def test_delete(self): | ||
# Test failed flows | ||
with patch("requests.post") as mock_post: | ||
|