Debian Codegraph @

src/auth0/management/tickets/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import typing
4 from json.decoder import JSONDecodeError
5
6 from ..core.api_error import ApiError
7 from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8 from ..core.http_response import AsyncHttpResponse, HttpResponse
9 from ..core.parse_error import ParsingError
10 from ..core.pydantic_utilities import parse_obj_as
11 from ..core.request_options import RequestOptions
12 from ..core.serialization import convert_and_respect_annotation_metadata
13 from ..errors.bad_request_error import BadRequestError
14 from ..errors.forbidden_error import ForbiddenError
15 from ..errors.not_found_error import NotFoundError
16 from ..errors.too_many_requests_error import TooManyRequestsError
17 from ..errors.unauthorized_error import UnauthorizedError
18 from ..types.change_password_ticket_identity import ChangePasswordTicketIdentity
19 from ..types.change_password_ticket_response_content import ChangePasswordTicketResponseContent
20 from ..types.identity import Identity
21 from ..types.verify_email_ticket_response_content import VerifyEmailTicketResponseContent
22 from pydantic import ValidationError
23
24 # this is used as the default value for optional parameters
25 OMIT = typing.cast(typing.Any, ...)
26
27
28 class RawTicketsClient:
29 def __init__(self, *, client_wrapper: SyncClientWrapper):
30 self._client_wrapper = client_wrapper
31
32 def verify_email(
33 self,
34 *,
35 user_id: str,
36 result_url: typing.Optional[str] = OMIT,
37 client_id: typing.Optional[str] = OMIT,
38 organization_id: typing.Optional[str] = OMIT,
39 ttl_sec: typing.Optional[int] = OMIT,
40 include_email_in_redirect: typing.Optional[bool] = OMIT,
41 identity: typing.Optional[Identity] = OMIT,
42 request_options: typing.Optional[RequestOptions] = None,
43 ) -> HttpResponse[VerifyEmailTicketResponseContent]:
44 """
45 Create an email verification ticket for a given user. An email verification ticket is a generated URL that the user can consume to verify their email address.
46
47 Parameters
48 ----------
49 user_id : str
50 user_id of for whom the ticket should be created.
51
52 result_url : typing.Optional[str]
53 URL the user will be redirected to in the classic Universal Login experience once the ticket is used. Cannot be specified when using client_id or organization_id.
54
55 client_id : typing.Optional[str]
56 ID of the client (application). If provided for tenants using the New Universal Login experience, the email template and UI displays application details, and the user is prompted to redirect to the application's <a target='' href='https://auth0.com/docs/authenticate/login/auth0-universal-login/configure-default-login-routes#completing-the-password-reset-flow'>default login route</a> after the ticket is used. client_id is required to use the <a target='' href='https://auth0.com/docs/customize/actions/flows-and-triggers/post-change-password-flow'>Password Reset Post Challenge</a> trigger.
57
58 organization_id : typing.Optional[str]
59 (Optional) Organization ID – the ID of the Organization. If provided, organization parameters will be made available to the email template and organization branding will be applied to the prompt. In addition, the redirect link in the prompt will include organization_id and organization_name query string parameters.
60
61 ttl_sec : typing.Optional[int]
62 Number of seconds for which the ticket is valid before expiration. If unspecified or set to 0, this value defaults to 432000 seconds (5 days).
63
64 include_email_in_redirect : typing.Optional[bool]
65 Whether to include the email address as part of the returnUrl in the reset_email (true), or not (false).
66
67 identity : typing.Optional[Identity]
68
69 request_options : typing.Optional[RequestOptions]
70 Request-specific configuration.
71
72 Returns
73 -------
74 HttpResponse[VerifyEmailTicketResponseContent]
75 Ticket successfully created.
76 """
77 _response = self._client_wrapper.httpx_client.request(
78 "tickets/email-verification",
79 method="POST",
80 json={
81 "result_url": result_url,
82 "user_id": user_id,
83 "client_id": client_id,
84 "organization_id": organization_id,
85 "ttl_sec": ttl_sec,
86 "includeEmailInRedirect": include_email_in_redirect,
87 "identity": convert_and_respect_annotation_metadata(
88 object_=identity, annotation=Identity, direction="write"
89 ),
90 },
91 headers={
92 "content-type": "application/json",
93 },
94 request_options=request_options,
95 omit=OMIT,
96 )
97 try:
98 if 200 <= _response.status_code < 300:
99 _data = typing.cast(
100 VerifyEmailTicketResponseContent,
101 parse_obj_as(
102 type_=VerifyEmailTicketResponseContent, # type: ignore
103 object_=_response.json(),
104 ),
105 )
106 return HttpResponse(response=_response, data=_data)
107 if _response.status_code == 400:
108 raise BadRequestError(
109 headers=dict(_response.headers),
110 body=typing.cast(
111 typing.Any,
112 parse_obj_as(
113 type_=typing.Any, # type: ignore
114 object_=_response.json(),
115 ),
116 ),
117 )
118 if _response.status_code == 401:
119 raise UnauthorizedError(
120 headers=dict(_response.headers),
121 body=typing.cast(
122 typing.Any,
123 parse_obj_as(
124 type_=typing.Any, # type: ignore
125 object_=_response.json(),
126 ),
127 ),
128 )
129 if _response.status_code == 403:
130 raise ForbiddenError(
131 headers=dict(_response.headers),
132 body=typing.cast(
133 typing.Any,
134 parse_obj_as(
135 type_=typing.Any, # type: ignore
136 object_=_response.json(),
137 ),
138 ),
139 )
140 if _response.status_code == 404:
141 raise NotFoundError(
142 headers=dict(_response.headers),
143 body=typing.cast(
144 typing.Any,
145 parse_obj_as(
146 type_=typing.Any, # type: ignore
147 object_=_response.json(),
148 ),
149 ),
150 )
151 if _response.status_code == 429:
152 raise TooManyRequestsError(
153 headers=dict(_response.headers),
154 body=typing.cast(
155 typing.Any,
156 parse_obj_as(
157 type_=typing.Any, # type: ignore
158 object_=_response.json(),
159 ),
160 ),
161 )
162 _response_json = _response.json()
163 except JSONDecodeError:
164 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
165 except ValidationError as e:
166 raise ParsingError(
167 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
168 )
169 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
170
171 def change_password(
172 self,
173 *,
174 result_url: typing.Optional[str] = OMIT,
175 user_id: typing.Optional[str] = OMIT,
176 client_id: typing.Optional[str] = OMIT,
177 organization_id: typing.Optional[str] = OMIT,
178 connection_id: typing.Optional[str] = OMIT,
179 email: typing.Optional[str] = OMIT,
180 ttl_sec: typing.Optional[int] = OMIT,
181 mark_email_as_verified: typing.Optional[bool] = OMIT,
182 include_email_in_redirect: typing.Optional[bool] = OMIT,
183 identity: typing.Optional[ChangePasswordTicketIdentity] = OMIT,
184 request_options: typing.Optional[RequestOptions] = None,
185 ) -> HttpResponse[ChangePasswordTicketResponseContent]:
186 """
187 Create a password change ticket for a given user. A password change ticket is a generated URL that the user can consume to start a reset password flow.
188
189 Note: This endpoint does not verify the given user’s identity. If you call this endpoint within your application, you must design your application to verify the user’s identity.
190
191 Parameters
192 ----------
193 result_url : typing.Optional[str]
194 URL the user will be redirected to in the classic Universal Login experience once the ticket is used. Cannot be specified when using organization_id. May be specified together with client_id when the tenant has a custom password reset page enabled and a password-reset-post-challenge Action bound.
195
196 user_id : typing.Optional[str]
197 user_id of for whom the ticket should be created.
198
199 client_id : typing.Optional[str]
200 ID of the client (application). If provided for tenants using the New Universal Login experience, the email template and UI displays application details, and the user is prompted to redirect to the application's <a target='' href='https://auth0.com/docs/authenticate/login/auth0-universal-login/configure-default-login-routes#completing-the-password-reset-flow'>default login route</a> after the ticket is used. client_id is required to use the <a target='' href='https://auth0.com/docs/customize/actions/flows-and-triggers/post-change-password-flow'>Password Reset Post Challenge</a> trigger.
201
202 organization_id : typing.Optional[str]
203 (Optional) Organization ID – the ID of the Organization. If provided, organization parameters will be made available to the email template and organization branding will be applied to the prompt. In addition, the redirect link in the prompt will include organization_id and organization_name query string parameters.
204
205 connection_id : typing.Optional[str]
206 ID of the connection. If provided, allows the user to be specified using email instead of user_id. If you set this value, you must also send the email parameter. You cannot send user_id when specifying a connection_id.
207
208 email : typing.Optional[str]
209 Email address of the user for whom the tickets should be created. Requires the connection_id parameter. Cannot be specified when using user_id.
210
211 ttl_sec : typing.Optional[int]
212 Number of seconds for which the ticket is valid before expiration. If unspecified or set to 0, this value defaults to 432000 seconds (5 days).
213
214 mark_email_as_verified : typing.Optional[bool]
215 Whether to set the email_verified attribute to true (true) or whether it should not be updated (false).
216
217 include_email_in_redirect : typing.Optional[bool]
218 Whether to include the email address as part of the returnUrl in the reset_email (true), or not (false).
219
220 identity : typing.Optional[ChangePasswordTicketIdentity]
221
222 request_options : typing.Optional[RequestOptions]
223 Request-specific configuration.
224
225 Returns
226 -------
227 HttpResponse[ChangePasswordTicketResponseContent]
228 Ticket successfully created.
229 """
230 _response = self._client_wrapper.httpx_client.request(
231 "tickets/password-change",
232 method="POST",
233 json={
234 "result_url": result_url,
235 "user_id": user_id,
236 "client_id": client_id,
237 "organization_id": organization_id,
238 "connection_id": connection_id,
239 "email": email,
240 "ttl_sec": ttl_sec,
241 "mark_email_as_verified": mark_email_as_verified,
242 "includeEmailInRedirect": include_email_in_redirect,
243 "identity": convert_and_respect_annotation_metadata(
244 object_=identity, annotation=ChangePasswordTicketIdentity, direction="write"
245 ),
246 },
247 headers={
248 "content-type": "application/json",
249 },
250 request_options=request_options,
251 omit=OMIT,
252 )
253 try:
254 if 200 <= _response.status_code < 300:
255 _data = typing.cast(
256 ChangePasswordTicketResponseContent,
257 parse_obj_as(
258 type_=ChangePasswordTicketResponseContent, # type: ignore
259 object_=_response.json(),
260 ),
261 )
262 return HttpResponse(response=_response, data=_data)
263 if _response.status_code == 400:
264 raise BadRequestError(
265 headers=dict(_response.headers),
266 body=typing.cast(
267 typing.Any,
268 parse_obj_as(
269 type_=typing.Any, # type: ignore
270 object_=_response.json(),
271 ),
272 ),
273 )
274 if _response.status_code == 401:
275 raise UnauthorizedError(
276 headers=dict(_response.headers),
277 body=typing.cast(
278 typing.Any,
279 parse_obj_as(
280 type_=typing.Any, # type: ignore
281 object_=_response.json(),
282 ),
283 ),
284 )
285 if _response.status_code == 403:
286 raise ForbiddenError(
287 headers=dict(_response.headers),
288 body=typing.cast(
289 typing.Any,
290 parse_obj_as(
291 type_=typing.Any, # type: ignore
292 object_=_response.json(),
293 ),
294 ),
295 )
296 if _response.status_code == 404:
297 raise NotFoundError(
298 headers=dict(_response.headers),
299 body=typing.cast(
300 typing.Any,
301 parse_obj_as(
302 type_=typing.Any, # type: ignore
303 object_=_response.json(),
304 ),
305 ),
306 )
307 if _response.status_code == 429:
308 raise TooManyRequestsError(
309 headers=dict(_response.headers),
310 body=typing.cast(
311 typing.Any,
312 parse_obj_as(
313 type_=typing.Any, # type: ignore
314 object_=_response.json(),
315 ),
316 ),
317 )
318 _response_json = _response.json()
319 except JSONDecodeError:
320 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
321 except ValidationError as e:
322 raise ParsingError(
323 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
324 )
325 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
326
327
328 class AsyncRawTicketsClient:
329 def __init__(self, *, client_wrapper: AsyncClientWrapper):
330 self._client_wrapper = client_wrapper
331
332 async def verify_email(
333 self,
334 *,
335 user_id: str,
336 result_url: typing.Optional[str] = OMIT,
337 client_id: typing.Optional[str] = OMIT,
338 organization_id: typing.Optional[str] = OMIT,
339 ttl_sec: typing.Optional[int] = OMIT,
340 include_email_in_redirect: typing.Optional[bool] = OMIT,
341 identity: typing.Optional[Identity] = OMIT,
342 request_options: typing.Optional[RequestOptions] = None,
343 ) -> AsyncHttpResponse[VerifyEmailTicketResponseContent]:
344 """
345 Create an email verification ticket for a given user. An email verification ticket is a generated URL that the user can consume to verify their email address.
346
347 Parameters
348 ----------
349 user_id : str
350 user_id of for whom the ticket should be created.
351
352 result_url : typing.Optional[str]
353 URL the user will be redirected to in the classic Universal Login experience once the ticket is used. Cannot be specified when using client_id or organization_id.
354
355 client_id : typing.Optional[str]
356 ID of the client (application). If provided for tenants using the New Universal Login experience, the email template and UI displays application details, and the user is prompted to redirect to the application's <a target='' href='https://auth0.com/docs/authenticate/login/auth0-universal-login/configure-default-login-routes#completing-the-password-reset-flow'>default login route</a> after the ticket is used. client_id is required to use the <a target='' href='https://auth0.com/docs/customize/actions/flows-and-triggers/post-change-password-flow'>Password Reset Post Challenge</a> trigger.
357
358 organization_id : typing.Optional[str]
359 (Optional) Organization ID – the ID of the Organization. If provided, organization parameters will be made available to the email template and organization branding will be applied to the prompt. In addition, the redirect link in the prompt will include organization_id and organization_name query string parameters.
360
361 ttl_sec : typing.Optional[int]
362 Number of seconds for which the ticket is valid before expiration. If unspecified or set to 0, this value defaults to 432000 seconds (5 days).
363
364 include_email_in_redirect : typing.Optional[bool]
365 Whether to include the email address as part of the returnUrl in the reset_email (true), or not (false).
366
367 identity : typing.Optional[Identity]
368
369 request_options : typing.Optional[RequestOptions]
370 Request-specific configuration.
371
372 Returns
373 -------
374 AsyncHttpResponse[VerifyEmailTicketResponseContent]
375 Ticket successfully created.
376 """
377 _response = await self._client_wrapper.httpx_client.request(
378 "tickets/email-verification",
379 method="POST",
380 json={
381 "result_url": result_url,
382 "user_id": user_id,
383 "client_id": client_id,
384 "organization_id": organization_id,
385 "ttl_sec": ttl_sec,
386 "includeEmailInRedirect": include_email_in_redirect,
387 "identity": convert_and_respect_annotation_metadata(
388 object_=identity, annotation=Identity, direction="write"
389 ),
390 },
391 headers={
392 "content-type": "application/json",
393 },
394 request_options=request_options,
395 omit=OMIT,
396 )
397 try:
398 if 200 <= _response.status_code < 300:
399 _data = typing.cast(
400 VerifyEmailTicketResponseContent,
401 parse_obj_as(
402 type_=VerifyEmailTicketResponseContent, # type: ignore
403 object_=_response.json(),
404 ),
405 )
406 return AsyncHttpResponse(response=_response, data=_data)
407 if _response.status_code == 400:
408 raise BadRequestError(
409 headers=dict(_response.headers),
410 body=typing.cast(
411 typing.Any,
412 parse_obj_as(
413 type_=typing.Any, # type: ignore
414 object_=_response.json(),
415 ),
416 ),
417 )
418 if _response.status_code == 401:
419 raise UnauthorizedError(
420 headers=dict(_response.headers),
421 body=typing.cast(
422 typing.Any,
423 parse_obj_as(
424 type_=typing.Any, # type: ignore
425 object_=_response.json(),
426 ),
427 ),
428 )
429 if _response.status_code == 403:
430 raise ForbiddenError(
431 headers=dict(_response.headers),
432 body=typing.cast(
433 typing.Any,
434 parse_obj_as(
435 type_=typing.Any, # type: ignore
436 object_=_response.json(),
437 ),
438 ),
439 )
440 if _response.status_code == 404:
441 raise NotFoundError(
442 headers=dict(_response.headers),
443 body=typing.cast(
444 typing.Any,
445 parse_obj_as(
446 type_=typing.Any, # type: ignore
447 object_=_response.json(),
448 ),
449 ),
450 )
451 if _response.status_code == 429:
452 raise TooManyRequestsError(
453 headers=dict(_response.headers),
454 body=typing.cast(
455 typing.Any,
456 parse_obj_as(
457 type_=typing.Any, # type: ignore
458 object_=_response.json(),
459 ),
460 ),
461 )
462 _response_json = _response.json()
463 except JSONDecodeError:
464 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
465 except ValidationError as e:
466 raise ParsingError(
467 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
468 )
469 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
470
471 async def change_password(
472 self,
473 *,
474 result_url: typing.Optional[str] = OMIT,
475 user_id: typing.Optional[str] = OMIT,
476 client_id: typing.Optional[str] = OMIT,
477 organization_id: typing.Optional[str] = OMIT,
478 connection_id: typing.Optional[str] = OMIT,
479 email: typing.Optional[str] = OMIT,
480 ttl_sec: typing.Optional[int] = OMIT,
481 mark_email_as_verified: typing.Optional[bool] = OMIT,
482 include_email_in_redirect: typing.Optional[bool] = OMIT,
483 identity: typing.Optional[ChangePasswordTicketIdentity] = OMIT,
484 request_options: typing.Optional[RequestOptions] = None,
485 ) -> AsyncHttpResponse[ChangePasswordTicketResponseContent]:
486 """
487 Create a password change ticket for a given user. A password change ticket is a generated URL that the user can consume to start a reset password flow.
488
489 Note: This endpoint does not verify the given user’s identity. If you call this endpoint within your application, you must design your application to verify the user’s identity.
490
491 Parameters
492 ----------
493 result_url : typing.Optional[str]
494 URL the user will be redirected to in the classic Universal Login experience once the ticket is used. Cannot be specified when using organization_id. May be specified together with client_id when the tenant has a custom password reset page enabled and a password-reset-post-challenge Action bound.
495
496 user_id : typing.Optional[str]
497 user_id of for whom the ticket should be created.
498
499 client_id : typing.Optional[str]
500 ID of the client (application). If provided for tenants using the New Universal Login experience, the email template and UI displays application details, and the user is prompted to redirect to the application's <a target='' href='https://auth0.com/docs/authenticate/login/auth0-universal-login/configure-default-login-routes#completing-the-password-reset-flow'>default login route</a> after the ticket is used. client_id is required to use the <a target='' href='https://auth0.com/docs/customize/actions/flows-and-triggers/post-change-password-flow'>Password Reset Post Challenge</a> trigger.
501
502 organization_id : typing.Optional[str]
503 (Optional) Organization ID – the ID of the Organization. If provided, organization parameters will be made available to the email template and organization branding will be applied to the prompt. In addition, the redirect link in the prompt will include organization_id and organization_name query string parameters.
504
505 connection_id : typing.Optional[str]
506 ID of the connection. If provided, allows the user to be specified using email instead of user_id. If you set this value, you must also send the email parameter. You cannot send user_id when specifying a connection_id.
507
508 email : typing.Optional[str]
509 Email address of the user for whom the tickets should be created. Requires the connection_id parameter. Cannot be specified when using user_id.
510
511 ttl_sec : typing.Optional[int]
512 Number of seconds for which the ticket is valid before expiration. If unspecified or set to 0, this value defaults to 432000 seconds (5 days).
513
514 mark_email_as_verified : typing.Optional[bool]
515 Whether to set the email_verified attribute to true (true) or whether it should not be updated (false).
516
517 include_email_in_redirect : typing.Optional[bool]
518 Whether to include the email address as part of the returnUrl in the reset_email (true), or not (false).
519
520 identity : typing.Optional[ChangePasswordTicketIdentity]
521
522 request_options : typing.Optional[RequestOptions]
523 Request-specific configuration.
524
525 Returns
526 -------
527 AsyncHttpResponse[ChangePasswordTicketResponseContent]
528 Ticket successfully created.
529 """
530 _response = await self._client_wrapper.httpx_client.request(
531 "tickets/password-change",
532 method="POST",
533 json={
534 "result_url": result_url,
535 "user_id": user_id,
536 "client_id": client_id,
537 "organization_id": organization_id,
538 "connection_id": connection_id,
539 "email": email,
540 "ttl_sec": ttl_sec,
541 "mark_email_as_verified": mark_email_as_verified,
542 "includeEmailInRedirect": include_email_in_redirect,
543 "identity": convert_and_respect_annotation_metadata(
544 object_=identity, annotation=ChangePasswordTicketIdentity, direction="write"
545 ),
546 },
547 headers={
548 "content-type": "application/json",
549 },
550 request_options=request_options,
551 omit=OMIT,
552 )
553 try:
554 if 200 <= _response.status_code < 300:
555 _data = typing.cast(
556 ChangePasswordTicketResponseContent,
557 parse_obj_as(
558 type_=ChangePasswordTicketResponseContent, # type: ignore
559 object_=_response.json(),
560 ),
561 )
562 return AsyncHttpResponse(response=_response, data=_data)
563 if _response.status_code == 400:
564 raise BadRequestError(
565 headers=dict(_response.headers),
566 body=typing.cast(
567 typing.Any,
568 parse_obj_as(
569 type_=typing.Any, # type: ignore
570 object_=_response.json(),
571 ),
572 ),
573 )
574 if _response.status_code == 401:
575 raise UnauthorizedError(
576 headers=dict(_response.headers),
577 body=typing.cast(
578 typing.Any,
579 parse_obj_as(
580 type_=typing.Any, # type: ignore
581 object_=_response.json(),
582 ),
583 ),
584 )
585 if _response.status_code == 403:
586 raise ForbiddenError(
587 headers=dict(_response.headers),
588 body=typing.cast(
589 typing.Any,
590 parse_obj_as(
591 type_=typing.Any, # type: ignore
592 object_=_response.json(),
593 ),
594 ),
595 )
596 if _response.status_code == 404:
597 raise NotFoundError(
598 headers=dict(_response.headers),
599 body=typing.cast(
600 typing.Any,
601 parse_obj_as(
602 type_=typing.Any, # type: ignore
603 object_=_response.json(),
604 ),
605 ),
606 )
607 if _response.status_code == 429:
608 raise TooManyRequestsError(
609 headers=dict(_response.headers),
610 body=typing.cast(
611 typing.Any,
612 parse_obj_as(
613 type_=typing.Any, # type: ignore
614 object_=_response.json(),
615 ),
616 ),
617 )
618 _response_json = _response.json()
619 except JSONDecodeError:
620 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
621 except ValidationError as e:
622 raise ParsingError(
623 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
624 )
625 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)