diff --git a/propelauth_py/__init__.py b/propelauth_py/__init__.py index 776ffc4..611e9a5 100644 --- a/propelauth_py/__init__.py +++ b/propelauth_py/__init__.py @@ -23,6 +23,7 @@ _disable_user_can_create_orgs, _validate_personal_api_key, _invite_user_to_org, + _resend_email_confirmation, ) from propelauth_py.api.org import ( _fetch_custom_role_mappings, @@ -115,6 +116,7 @@ "fetch_users_in_org", "create_user", "invite_user_to_org", + "resend_email_confirmation", "update_user_email", "update_user_metadata", "update_user_password", @@ -282,6 +284,13 @@ def invite_user_to_org(email, org_id, role, additional_roles=[]): additional_roles, ) + def resend_email_confirmation(user_id): + return _resend_email_confirmation( + auth_url, + integration_api_key, + user_id, + ) + def update_user_email(user_id, new_email, require_email_confirmation): return _update_user_email( auth_url, @@ -433,7 +442,9 @@ def delete_org(org_id): return _delete_org(auth_url, integration_api_key, org_id) def add_user_to_org(user_id, org_id, role, additional_roles=[]): - return _add_user_to_org(auth_url, integration_api_key, user_id, org_id, role, additional_roles) + return _add_user_to_org( + auth_url, integration_api_key, user_id, org_id, role, additional_roles + ) def remove_user_from_org(user_id, org_id): return _remove_user_from_org(auth_url, integration_api_key, user_id, org_id) @@ -598,6 +609,7 @@ def validate_api_key(api_key_token): fetch_users_in_org=fetch_users_in_org, create_user=create_user, invite_user_to_org=invite_user_to_org, + resend_email_confirmation=resend_email_confirmation, update_user_email=update_user_email, update_user_metadata=update_user_metadata, update_user_password=update_user_password, diff --git a/propelauth_py/api/user.py b/propelauth_py/api/user.py index 5f5bf89..b396437 100644 --- a/propelauth_py/api/user.py +++ b/propelauth_py/api/user.py @@ -309,7 +309,9 @@ def _disable_user_2fa(auth_url, integration_api_key, user_id): return True -def _invite_user_to_org(auth_url, integration_api_key, email, org_id, role, additional_roles=[]): +def _invite_user_to_org( + auth_url, integration_api_key, email, org_id, role, additional_roles=[] +): if not _is_valid_id(org_id): return False @@ -338,6 +340,35 @@ def _invite_user_to_org(auth_url, integration_api_key, email, org_id, role, addi return response.text + +def _resend_email_confirmation(auth_url, integration_api_key, user_id): + if not _is_valid_id(user_id): + return False + + endpoint_path = "/api/backend/v1/resend_email_confirmation" + url = auth_url + endpoint_path + json = { + "user_id": user_id, + } + response = requests.post(url, json=json, 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 response.status_code == 429: + raise RuntimeError("Too many requests, please try again later.") + elif response.status_code == 400: + if response.json().get("user_facing_error"): + raise ValueError(response.json().get("user_facing_error")) + else: + raise RuntimeError("Unknown error when resending email confirmation") + elif not response.ok: + raise RuntimeError("Unknown error when resending email confirmation") + + return True + + #################### # PATCH/PUT # #################### @@ -399,9 +430,9 @@ def _update_user_password( url = auth_url + f"{ENDPOINT_PATH}/{user_id}/password" json = {"password": password} if ask_user_to_update_password_on_login is not None: - json[ - "ask_user_to_update_password_on_login" - ] = ask_user_to_update_password_on_login + json["ask_user_to_update_password_on_login"] = ( + ask_user_to_update_password_on_login + ) response = requests.put(url, json=json, auth=_ApiKeyAuth(integration_api_key)) if response.status_code == 401: diff --git a/setup.py b/setup.py index f211a81..e08c003 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name="propelauth-py", - version="3.1.14", + version="3.1.15", description="A python authentication library", long_description=README, long_description_content_type="text/markdown", diff --git a/tests/test_init_base_auth.py b/tests/test_init_base_auth.py index d05a486..3a032d4 100644 --- a/tests/test_init_base_auth.py +++ b/tests/test_init_base_auth.py @@ -23,6 +23,7 @@ _disable_user_can_create_orgs, _validate_personal_api_key, _invite_user_to_org, + _resend_email_confirmation, ) from propelauth_py.api.org import ( _fetch_custom_role_mappings, @@ -100,6 +101,7 @@ _change_user_role_in_org, _delete_org, _invite_user_to_org, + _resend_email_confirmation, ]