Skip to content

Commit

Permalink
feat(user): add logout_all_user_sessions api request
Browse files Browse the repository at this point in the history
  • Loading branch information
itailevi98 committed Jun 14, 2024
1 parent ce4c947 commit 51a9736
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
14 changes: 12 additions & 2 deletions propelauth_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
_fetch_users_by_query,
_fetch_users_in_org,
_create_user,
_logout_all_user_sessions,
_update_user_email,
_update_user_metadata,
_delete_user,
Expand Down Expand Up @@ -137,6 +138,7 @@
"disable_user_2fa",
"enable_user_can_create_orgs",
"disable_user_can_create_orgs",
"logout_all_user_sessions",
"allow_org_to_setup_saml_connection",
"disallow_org_to_setup_saml_connection",
"fetch_api_key",
Expand Down Expand Up @@ -212,7 +214,7 @@ def fetch_org_by_query(
order_by,
name,
)

def fetch_custom_role_mappings():
return _fetch_custom_role_mappings(
auth_url,
Expand Down Expand Up @@ -291,6 +293,13 @@ def resend_email_confirmation(user_id):
user_id,
)

def logout_all_user_sessions(user_id):
return _logout_all_user_sessions(
auth_url,
integration_api_key,
user_id,
)

def update_user_email(user_id, new_email, require_email_confirmation):
return _update_user_email(
auth_url,
Expand Down Expand Up @@ -429,7 +438,7 @@ def update_org_metadata(
members_must_have_email_domain_match=members_must_have_email_domain_match,
domain=domain,
)

def subscribe_org_to_role_mapping(org_id, custom_role_mapping_name):
return _subscribe_org_to_role_mapping(
auth_url,
Expand Down Expand Up @@ -630,6 +639,7 @@ def validate_api_key(api_key_token):
disable_user_2fa=disable_user_2fa,
enable_user_can_create_orgs=enable_user_can_create_orgs,
disable_user_can_create_orgs=disable_user_can_create_orgs,
logout_all_user_sessions=logout_all_user_sessions,
allow_org_to_setup_saml_connection=allow_org_to_setup_saml_connection,
disallow_org_to_setup_saml_connection=disallow_org_to_setup_saml_connection,
# api key functions
Expand Down
17 changes: 17 additions & 0 deletions propelauth_py/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,23 @@ def _resend_email_confirmation(auth_url, integration_api_key, user_id):
return True


def _logout_all_user_sessions(auth_url, integration_api_key, user_id):
if not _is_valid_id(user_id):
return False

url = auth_url + f"{ENDPOINT_PATH}/{user_id}/logout_all_sessions"
response = requests.post(url, auth=_ApiKeyAuth(integration_api_key))

if response.status_code == 401:
raise ValueError("integration_api_key is incorrect")
elif response.status_code == 404:
return False
elif not response.ok:
raise RuntimeError("Unknown error when logging out all user sessions")

return True


####################
# PATCH/PUT #
####################
Expand Down
2 changes: 2 additions & 0 deletions tests/test_init_base_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
_validate_personal_api_key,
_invite_user_to_org,
_resend_email_confirmation,
_logout_all_user_sessions,
)
from propelauth_py.api.org import (
_fetch_custom_role_mappings,
Expand Down Expand Up @@ -102,6 +103,7 @@
_delete_org,
_invite_user_to_org,
_resend_email_confirmation,
_logout_all_user_sessions,
]


Expand Down

0 comments on commit 51a9736

Please sign in to comment.