From 09c1c0c4bc27a77a076125b36f4f53131266d705 Mon Sep 17 00:00:00 2001 From: aviadl Date: Wed, 16 Apr 2025 21:39:50 +0300 Subject: [PATCH] Add template ID and provider ID to update user requests related to https://github.com/descope/etc/issues/10011 --- .pre-commit-config.yaml | 4 ++-- descope/authmethod/enchantedlink.py | 11 ++++++++++- descope/authmethod/magiclink.py | 22 ++++++++++++++++++++-- descope/authmethod/otp.py | 22 ++++++++++++++++++++-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 320f06df5..54a2fb293 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/pycqa/flake8 - rev: 7.1.2 + rev: 7.2.0 hooks: - id: flake8 additional_dependencies: [Flake8-pyproject] @@ -52,7 +52,7 @@ repos: - id: tox-ini-fmt args: ["-p", "type"] - repo: https://github.com/gitleaks/gitleaks - rev: v8.24.2 + rev: v8.24.3 hooks: - id: gitleaks - repo: local diff --git a/descope/authmethod/enchantedlink.py b/descope/authmethod/enchantedlink.py index 28d133c33..b461aa058 100644 --- a/descope/authmethod/enchantedlink.py +++ b/descope/authmethod/enchantedlink.py @@ -107,6 +107,8 @@ def update_user_email( add_to_login_ids: bool = False, on_merge_use_existing: bool = False, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> dict: if not login_id: raise AuthException( @@ -116,7 +118,8 @@ def update_user_email( Auth.validate_email(email) body = EnchantedLink._compose_update_user_email_body( - login_id, email, add_to_login_ids, on_merge_use_existing, template_options + login_id, email, add_to_login_ids, on_merge_use_existing, + template_options, template_id, provider_id ) uri = EndpointsV1.update_user_email_enchantedlink_path response = self._auth.do_post(uri, body, None, refresh_token) @@ -181,6 +184,8 @@ def _compose_update_user_email_body( add_to_login_ids: bool, on_merge_use_existing: bool, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> dict: body: dict[str, str | bool | dict] = { "loginId": login_id, @@ -190,6 +195,10 @@ def _compose_update_user_email_body( } if template_options is not None: body["templateOptions"] = template_options + if template_id is not None: + body["templateId"] = template_id + if provider_id is not None: + body["providerId"] = provider_id return body diff --git a/descope/authmethod/magiclink.py b/descope/authmethod/magiclink.py index 5d1d7ed59..432c3356c 100644 --- a/descope/authmethod/magiclink.py +++ b/descope/authmethod/magiclink.py @@ -106,6 +106,8 @@ def update_user_email( add_to_login_ids: bool = False, on_merge_use_existing: bool = False, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> str: if not login_id: raise AuthException( @@ -115,7 +117,8 @@ def update_user_email( Auth.validate_email(email) body = MagicLink._compose_update_user_email_body( - login_id, email, add_to_login_ids, on_merge_use_existing, template_options + login_id, email, add_to_login_ids, on_merge_use_existing, + template_options, template_id, provider_id ) uri = EndpointsV1.update_user_email_magiclink_path response = self._auth.do_post(uri, body, None, refresh_token) @@ -130,6 +133,8 @@ def update_user_phone( add_to_login_ids: bool = False, on_merge_use_existing: bool = False, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> str: if not login_id: raise AuthException( @@ -139,7 +144,8 @@ def update_user_phone( Auth.validate_phone(method, phone) body = MagicLink._compose_update_user_phone_body( - login_id, phone, add_to_login_ids, on_merge_use_existing, template_options + login_id, phone, add_to_login_ids, on_merge_use_existing, + template_options, template_id, provider_id ) uri = EndpointsV1.update_user_phone_magiclink_path response = self._auth.do_post(uri, body, None, refresh_token) @@ -203,6 +209,8 @@ def _compose_update_user_email_body( add_to_login_ids: bool, on_merge_use_existing: bool, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> dict: body: dict[str, str | bool | dict] = { "loginId": login_id, @@ -212,6 +220,10 @@ def _compose_update_user_email_body( } if template_options is not None: body["templateOptions"] = template_options + if template_id is not None: + body["templateId"] = template_id + if provider_id is not None: + body["providerId"] = provider_id return body @@ -222,6 +234,8 @@ def _compose_update_user_phone_body( add_to_login_ids: bool, on_merge_use_existing: bool, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> dict: body: dict[str, str | bool | dict] = { "loginId": login_id, @@ -231,5 +245,9 @@ def _compose_update_user_phone_body( } if template_options is not None: body["templateOptions"] = template_options + if template_id is not None: + body["templateId"] = template_id + if provider_id is not None: + body["providerId"] = provider_id return body diff --git a/descope/authmethod/otp.py b/descope/authmethod/otp.py index 421d8a587..5a9a38cf0 100644 --- a/descope/authmethod/otp.py +++ b/descope/authmethod/otp.py @@ -174,6 +174,8 @@ def update_user_email( add_to_login_ids: bool = False, on_merge_use_existing: bool = False, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> str: """ Update the email address of an end user, after verifying the authenticity of the end user using OTP. @@ -196,7 +198,8 @@ def update_user_email( uri = EndpointsV1.update_user_email_otp_path body = OTP._compose_update_user_email_body( - login_id, email, add_to_login_ids, on_merge_use_existing, template_options + login_id, email, add_to_login_ids, on_merge_use_existing, + template_options, template_id, provider_id ) response = self._auth.do_post(uri, body, None, refresh_token) return Auth.extract_masked_address(response.json(), DeliveryMethod.EMAIL) @@ -210,6 +213,8 @@ def update_user_phone( add_to_login_ids: bool = False, on_merge_use_existing: bool = False, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> str: """ Update the phone number of an existing end user, after verifying the authenticity of the end user using OTP. @@ -236,7 +241,8 @@ def update_user_phone( uri = OTP._compose_update_phone_url(method) body = OTP._compose_update_user_phone_body( - login_id, phone, add_to_login_ids, on_merge_use_existing, template_options + login_id, phone, add_to_login_ids, on_merge_use_existing, + template_options, template_id, provider_id ) response = self._auth.do_post(uri, body, None, refresh_token) return Auth.extract_masked_address(response.json(), method) @@ -299,6 +305,8 @@ def _compose_update_user_email_body( add_to_login_ids: bool, on_merge_use_existing: bool, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> dict: body: dict[str, str | bool | dict] = { "loginId": login_id, @@ -308,6 +316,10 @@ def _compose_update_user_email_body( } if template_options is not None: body["templateOptions"] = template_options + if template_id is not None: + body["templateId"] = template_id + if provider_id is not None: + body["providerId"] = provider_id return body @@ -318,6 +330,8 @@ def _compose_update_user_phone_body( add_to_login_ids: bool, on_merge_use_existing: bool, template_options: dict | None = None, + template_id: str | None = None, + provider_id: str | None = None, ) -> dict: body: dict[str, str | bool | dict] = { "loginId": login_id, @@ -327,5 +341,9 @@ def _compose_update_user_phone_body( } if template_options is not None: body["templateOptions"] = template_options + if template_id is not None: + body["templateId"] = template_id + if provider_id is not None: + body["providerId"] = provider_id return body