Skip to content

Commit e5aef4c

Browse files
authored
Add template ID and provider ID to update user requests (#549)
related to descope/etc#10011
1 parent cd2db20 commit e5aef4c

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
- id: pyupgrade
3030
args: [--py38-plus]
3131
- repo: https://github.com/pycqa/flake8
32-
rev: 7.1.2
32+
rev: 7.2.0
3333
hooks:
3434
- id: flake8
3535
additional_dependencies: [Flake8-pyproject]
@@ -52,7 +52,7 @@ repos:
5252
- id: tox-ini-fmt
5353
args: ["-p", "type"]
5454
- repo: https://github.com/gitleaks/gitleaks
55-
rev: v8.24.2
55+
rev: v8.24.3
5656
hooks:
5757
- id: gitleaks
5858
- repo: local

descope/authmethod/enchantedlink.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def update_user_email(
107107
add_to_login_ids: bool = False,
108108
on_merge_use_existing: bool = False,
109109
template_options: dict | None = None,
110+
template_id: str | None = None,
111+
provider_id: str | None = None,
110112
) -> dict:
111113
if not login_id:
112114
raise AuthException(
@@ -116,7 +118,8 @@ def update_user_email(
116118
Auth.validate_email(email)
117119

118120
body = EnchantedLink._compose_update_user_email_body(
119-
login_id, email, add_to_login_ids, on_merge_use_existing, template_options
121+
login_id, email, add_to_login_ids, on_merge_use_existing,
122+
template_options, template_id, provider_id
120123
)
121124
uri = EndpointsV1.update_user_email_enchantedlink_path
122125
response = self._auth.do_post(uri, body, None, refresh_token)
@@ -181,6 +184,8 @@ def _compose_update_user_email_body(
181184
add_to_login_ids: bool,
182185
on_merge_use_existing: bool,
183186
template_options: dict | None = None,
187+
template_id: str | None = None,
188+
provider_id: str | None = None,
184189
) -> dict:
185190
body: dict[str, str | bool | dict] = {
186191
"loginId": login_id,
@@ -190,6 +195,10 @@ def _compose_update_user_email_body(
190195
}
191196
if template_options is not None:
192197
body["templateOptions"] = template_options
198+
if template_id is not None:
199+
body["templateId"] = template_id
200+
if provider_id is not None:
201+
body["providerId"] = provider_id
193202

194203
return body
195204

descope/authmethod/magiclink.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def update_user_email(
106106
add_to_login_ids: bool = False,
107107
on_merge_use_existing: bool = False,
108108
template_options: dict | None = None,
109+
template_id: str | None = None,
110+
provider_id: str | None = None,
109111
) -> str:
110112
if not login_id:
111113
raise AuthException(
@@ -115,7 +117,8 @@ def update_user_email(
115117
Auth.validate_email(email)
116118

117119
body = MagicLink._compose_update_user_email_body(
118-
login_id, email, add_to_login_ids, on_merge_use_existing, template_options
120+
login_id, email, add_to_login_ids, on_merge_use_existing,
121+
template_options, template_id, provider_id
119122
)
120123
uri = EndpointsV1.update_user_email_magiclink_path
121124
response = self._auth.do_post(uri, body, None, refresh_token)
@@ -130,6 +133,8 @@ def update_user_phone(
130133
add_to_login_ids: bool = False,
131134
on_merge_use_existing: bool = False,
132135
template_options: dict | None = None,
136+
template_id: str | None = None,
137+
provider_id: str | None = None,
133138
) -> str:
134139
if not login_id:
135140
raise AuthException(
@@ -139,7 +144,8 @@ def update_user_phone(
139144
Auth.validate_phone(method, phone)
140145

141146
body = MagicLink._compose_update_user_phone_body(
142-
login_id, phone, add_to_login_ids, on_merge_use_existing, template_options
147+
login_id, phone, add_to_login_ids, on_merge_use_existing,
148+
template_options, template_id, provider_id
143149
)
144150
uri = EndpointsV1.update_user_phone_magiclink_path
145151
response = self._auth.do_post(uri, body, None, refresh_token)
@@ -203,6 +209,8 @@ def _compose_update_user_email_body(
203209
add_to_login_ids: bool,
204210
on_merge_use_existing: bool,
205211
template_options: dict | None = None,
212+
template_id: str | None = None,
213+
provider_id: str | None = None,
206214
) -> dict:
207215
body: dict[str, str | bool | dict] = {
208216
"loginId": login_id,
@@ -212,6 +220,10 @@ def _compose_update_user_email_body(
212220
}
213221
if template_options is not None:
214222
body["templateOptions"] = template_options
223+
if template_id is not None:
224+
body["templateId"] = template_id
225+
if provider_id is not None:
226+
body["providerId"] = provider_id
215227

216228
return body
217229

@@ -222,6 +234,8 @@ def _compose_update_user_phone_body(
222234
add_to_login_ids: bool,
223235
on_merge_use_existing: bool,
224236
template_options: dict | None = None,
237+
template_id: str | None = None,
238+
provider_id: str | None = None,
225239
) -> dict:
226240
body: dict[str, str | bool | dict] = {
227241
"loginId": login_id,
@@ -231,5 +245,9 @@ def _compose_update_user_phone_body(
231245
}
232246
if template_options is not None:
233247
body["templateOptions"] = template_options
248+
if template_id is not None:
249+
body["templateId"] = template_id
250+
if provider_id is not None:
251+
body["providerId"] = provider_id
234252

235253
return body

descope/authmethod/otp.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ def update_user_email(
174174
add_to_login_ids: bool = False,
175175
on_merge_use_existing: bool = False,
176176
template_options: dict | None = None,
177+
template_id: str | None = None,
178+
provider_id: str | None = None,
177179
) -> str:
178180
"""
179181
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(
196198

197199
uri = EndpointsV1.update_user_email_otp_path
198200
body = OTP._compose_update_user_email_body(
199-
login_id, email, add_to_login_ids, on_merge_use_existing, template_options
201+
login_id, email, add_to_login_ids, on_merge_use_existing,
202+
template_options, template_id, provider_id
200203
)
201204
response = self._auth.do_post(uri, body, None, refresh_token)
202205
return Auth.extract_masked_address(response.json(), DeliveryMethod.EMAIL)
@@ -210,6 +213,8 @@ def update_user_phone(
210213
add_to_login_ids: bool = False,
211214
on_merge_use_existing: bool = False,
212215
template_options: dict | None = None,
216+
template_id: str | None = None,
217+
provider_id: str | None = None,
213218
) -> str:
214219
"""
215220
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(
236241

237242
uri = OTP._compose_update_phone_url(method)
238243
body = OTP._compose_update_user_phone_body(
239-
login_id, phone, add_to_login_ids, on_merge_use_existing, template_options
244+
login_id, phone, add_to_login_ids, on_merge_use_existing,
245+
template_options, template_id, provider_id
240246
)
241247
response = self._auth.do_post(uri, body, None, refresh_token)
242248
return Auth.extract_masked_address(response.json(), method)
@@ -299,6 +305,8 @@ def _compose_update_user_email_body(
299305
add_to_login_ids: bool,
300306
on_merge_use_existing: bool,
301307
template_options: dict | None = None,
308+
template_id: str | None = None,
309+
provider_id: str | None = None,
302310
) -> dict:
303311
body: dict[str, str | bool | dict] = {
304312
"loginId": login_id,
@@ -308,6 +316,10 @@ def _compose_update_user_email_body(
308316
}
309317
if template_options is not None:
310318
body["templateOptions"] = template_options
319+
if template_id is not None:
320+
body["templateId"] = template_id
321+
if provider_id is not None:
322+
body["providerId"] = provider_id
311323

312324
return body
313325

@@ -318,6 +330,8 @@ def _compose_update_user_phone_body(
318330
add_to_login_ids: bool,
319331
on_merge_use_existing: bool,
320332
template_options: dict | None = None,
333+
template_id: str | None = None,
334+
provider_id: str | None = None,
321335
) -> dict:
322336
body: dict[str, str | bool | dict] = {
323337
"loginId": login_id,
@@ -327,5 +341,9 @@ def _compose_update_user_phone_body(
327341
}
328342
if template_options is not None:
329343
body["templateOptions"] = template_options
344+
if template_id is not None:
345+
body["templateId"] = template_id
346+
if provider_id is not None:
347+
body["providerId"] = provider_id
330348

331349
return body

0 commit comments

Comments
 (0)