Debian Codegraph @

src/auth0/management/guardian/enrollments/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.jsonable_encoder import encode_path_param
10 from ...core.parse_error import ParsingError
11 from ...core.pydantic_utilities import parse_obj_as
12 from ...core.request_options import RequestOptions
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.unauthorized_error import UnauthorizedError
17 from ...types.create_guardian_enrollment_ticket_response_content import CreateGuardianEnrollmentTicketResponseContent
18 from ...types.get_guardian_enrollment_response_content import GetGuardianEnrollmentResponseContent
19 from ...types.guardian_enrollment_factor_enum import GuardianEnrollmentFactorEnum
20 from pydantic import ValidationError
21
22 # this is used as the default value for optional parameters
23 OMIT = typing.cast(typing.Any, ...)
24
25
26 class RawEnrollmentsClient:
27 def __init__(self, *, client_wrapper: SyncClientWrapper):
28 self._client_wrapper = client_wrapper
29
30 def create_ticket(
31 self,
32 *,
33 user_id: str,
34 email: typing.Optional[str] = OMIT,
35 send_mail: typing.Optional[bool] = OMIT,
36 email_locale: typing.Optional[str] = OMIT,
37 factor: typing.Optional[GuardianEnrollmentFactorEnum] = OMIT,
38 allow_multiple_enrollments: typing.Optional[bool] = OMIT,
39 request_options: typing.Optional[RequestOptions] = None,
40 ) -> HttpResponse[CreateGuardianEnrollmentTicketResponseContent]:
41 """
42 Create a [multi-factor authentication (MFA) enrollment ticket](https://auth0.com/docs/secure/multi-factor-authentication/auth0-guardian/create-custom-enrollment-tickets), and optionally send an email with the created ticket to a given user. Enrollment tickets can specify which factor users must enroll with or allow existing MFA users to enroll in additional factors.
43
44 Parameters
45 ----------
46 user_id : str
47 user_id for the enrollment ticket
48
49 email : typing.Optional[str]
50 alternate email to which the enrollment email will be sent. Optional - by default, the email will be sent to the user's default address
51
52 send_mail : typing.Optional[bool]
53 Send an email to the user to start the enrollment
54
55 email_locale : typing.Optional[str]
56 Optional. Specify the locale of the enrollment email. Used with send_email.
57
58 factor : typing.Optional[GuardianEnrollmentFactorEnum]
59
60 allow_multiple_enrollments : typing.Optional[bool]
61 Optional. Allows a user who has previously enrolled in MFA to enroll with additional factors.<br />Note: Parameter can only be used with Universal Login; it cannot be used with Classic Login or custom MFA pages.
62
63 request_options : typing.Optional[RequestOptions]
64 Request-specific configuration.
65
66 Returns
67 -------
68 HttpResponse[CreateGuardianEnrollmentTicketResponseContent]
69 Enrollment ticket successfully created.
70 """
71 _response = self._client_wrapper.httpx_client.request(
72 "guardian/enrollments/ticket",
73 method="POST",
74 json={
75 "user_id": user_id,
76 "email": email,
77 "send_mail": send_mail,
78 "email_locale": email_locale,
79 "factor": factor,
80 "allow_multiple_enrollments": allow_multiple_enrollments,
81 },
82 headers={
83 "content-type": "application/json",
84 },
85 request_options=request_options,
86 omit=OMIT,
87 )
88 try:
89 if 200 <= _response.status_code < 300:
90 _data = typing.cast(
91 CreateGuardianEnrollmentTicketResponseContent,
92 parse_obj_as(
93 type_=CreateGuardianEnrollmentTicketResponseContent, # type: ignore
94 object_=_response.json(),
95 ),
96 )
97 return HttpResponse(response=_response, data=_data)
98 if _response.status_code == 400:
99 raise BadRequestError(
100 headers=dict(_response.headers),
101 body=typing.cast(
102 typing.Any,
103 parse_obj_as(
104 type_=typing.Any, # type: ignore
105 object_=_response.json(),
106 ),
107 ),
108 )
109 if _response.status_code == 401:
110 raise UnauthorizedError(
111 headers=dict(_response.headers),
112 body=typing.cast(
113 typing.Any,
114 parse_obj_as(
115 type_=typing.Any, # type: ignore
116 object_=_response.json(),
117 ),
118 ),
119 )
120 if _response.status_code == 403:
121 raise ForbiddenError(
122 headers=dict(_response.headers),
123 body=typing.cast(
124 typing.Any,
125 parse_obj_as(
126 type_=typing.Any, # type: ignore
127 object_=_response.json(),
128 ),
129 ),
130 )
131 if _response.status_code == 404:
132 raise NotFoundError(
133 headers=dict(_response.headers),
134 body=typing.cast(
135 typing.Any,
136 parse_obj_as(
137 type_=typing.Any, # type: ignore
138 object_=_response.json(),
139 ),
140 ),
141 )
142 _response_json = _response.json()
143 except JSONDecodeError:
144 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
145 except ValidationError as e:
146 raise ParsingError(
147 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
148 )
149 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
150
151 def get(
152 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
153 ) -> HttpResponse[GetGuardianEnrollmentResponseContent]:
154 """
155 Retrieve details, such as status and type, for a specific multi-factor authentication enrollment registered to a user account.
156
157 Parameters
158 ----------
159 id : str
160 ID of the enrollment to be retrieve.
161
162 request_options : typing.Optional[RequestOptions]
163 Request-specific configuration.
164
165 Returns
166 -------
167 HttpResponse[GetGuardianEnrollmentResponseContent]
168 Enrollment successfully retrieved.
169 """
170 _response = self._client_wrapper.httpx_client.request(
171 f"guardian/enrollments/{encode_path_param(id)}",
172 method="GET",
173 request_options=request_options,
174 )
175 try:
176 if 200 <= _response.status_code < 300:
177 _data = typing.cast(
178 GetGuardianEnrollmentResponseContent,
179 parse_obj_as(
180 type_=GetGuardianEnrollmentResponseContent, # type: ignore
181 object_=_response.json(),
182 ),
183 )
184 return HttpResponse(response=_response, data=_data)
185 if _response.status_code == 400:
186 raise BadRequestError(
187 headers=dict(_response.headers),
188 body=typing.cast(
189 typing.Any,
190 parse_obj_as(
191 type_=typing.Any, # type: ignore
192 object_=_response.json(),
193 ),
194 ),
195 )
196 if _response.status_code == 401:
197 raise UnauthorizedError(
198 headers=dict(_response.headers),
199 body=typing.cast(
200 typing.Any,
201 parse_obj_as(
202 type_=typing.Any, # type: ignore
203 object_=_response.json(),
204 ),
205 ),
206 )
207 if _response.status_code == 403:
208 raise ForbiddenError(
209 headers=dict(_response.headers),
210 body=typing.cast(
211 typing.Any,
212 parse_obj_as(
213 type_=typing.Any, # type: ignore
214 object_=_response.json(),
215 ),
216 ),
217 )
218 _response_json = _response.json()
219 except JSONDecodeError:
220 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
221 except ValidationError as e:
222 raise ParsingError(
223 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
224 )
225 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
226
227 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
228 """
229 Remove a specific multi-factor authentication (MFA) enrollment from a user's account. This allows the user to re-enroll with MFA. For more information, review [Reset User Multi-Factor Authentication and Recovery Codes](https://auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa).
230
231 Parameters
232 ----------
233 id : str
234 ID of the enrollment to be deleted.
235
236 request_options : typing.Optional[RequestOptions]
237 Request-specific configuration.
238
239 Returns
240 -------
241 HttpResponse[None]
242 """
243 _response = self._client_wrapper.httpx_client.request(
244 f"guardian/enrollments/{encode_path_param(id)}",
245 method="DELETE",
246 request_options=request_options,
247 )
248 try:
249 if 200 <= _response.status_code < 300:
250 return HttpResponse(response=_response, data=None)
251 if _response.status_code == 400:
252 raise BadRequestError(
253 headers=dict(_response.headers),
254 body=typing.cast(
255 typing.Any,
256 parse_obj_as(
257 type_=typing.Any, # type: ignore
258 object_=_response.json(),
259 ),
260 ),
261 )
262 if _response.status_code == 401:
263 raise UnauthorizedError(
264 headers=dict(_response.headers),
265 body=typing.cast(
266 typing.Any,
267 parse_obj_as(
268 type_=typing.Any, # type: ignore
269 object_=_response.json(),
270 ),
271 ),
272 )
273 if _response.status_code == 403:
274 raise ForbiddenError(
275 headers=dict(_response.headers),
276 body=typing.cast(
277 typing.Any,
278 parse_obj_as(
279 type_=typing.Any, # type: ignore
280 object_=_response.json(),
281 ),
282 ),
283 )
284 _response_json = _response.json()
285 except JSONDecodeError:
286 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
287 except ValidationError as e:
288 raise ParsingError(
289 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
290 )
291 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
292
293
294 class AsyncRawEnrollmentsClient:
295 def __init__(self, *, client_wrapper: AsyncClientWrapper):
296 self._client_wrapper = client_wrapper
297
298 async def create_ticket(
299 self,
300 *,
301 user_id: str,
302 email: typing.Optional[str] = OMIT,
303 send_mail: typing.Optional[bool] = OMIT,
304 email_locale: typing.Optional[str] = OMIT,
305 factor: typing.Optional[GuardianEnrollmentFactorEnum] = OMIT,
306 allow_multiple_enrollments: typing.Optional[bool] = OMIT,
307 request_options: typing.Optional[RequestOptions] = None,
308 ) -> AsyncHttpResponse[CreateGuardianEnrollmentTicketResponseContent]:
309 """
310 Create a [multi-factor authentication (MFA) enrollment ticket](https://auth0.com/docs/secure/multi-factor-authentication/auth0-guardian/create-custom-enrollment-tickets), and optionally send an email with the created ticket to a given user. Enrollment tickets can specify which factor users must enroll with or allow existing MFA users to enroll in additional factors.
311
312 Parameters
313 ----------
314 user_id : str
315 user_id for the enrollment ticket
316
317 email : typing.Optional[str]
318 alternate email to which the enrollment email will be sent. Optional - by default, the email will be sent to the user's default address
319
320 send_mail : typing.Optional[bool]
321 Send an email to the user to start the enrollment
322
323 email_locale : typing.Optional[str]
324 Optional. Specify the locale of the enrollment email. Used with send_email.
325
326 factor : typing.Optional[GuardianEnrollmentFactorEnum]
327
328 allow_multiple_enrollments : typing.Optional[bool]
329 Optional. Allows a user who has previously enrolled in MFA to enroll with additional factors.<br />Note: Parameter can only be used with Universal Login; it cannot be used with Classic Login or custom MFA pages.
330
331 request_options : typing.Optional[RequestOptions]
332 Request-specific configuration.
333
334 Returns
335 -------
336 AsyncHttpResponse[CreateGuardianEnrollmentTicketResponseContent]
337 Enrollment ticket successfully created.
338 """
339 _response = await self._client_wrapper.httpx_client.request(
340 "guardian/enrollments/ticket",
341 method="POST",
342 json={
343 "user_id": user_id,
344 "email": email,
345 "send_mail": send_mail,
346 "email_locale": email_locale,
347 "factor": factor,
348 "allow_multiple_enrollments": allow_multiple_enrollments,
349 },
350 headers={
351 "content-type": "application/json",
352 },
353 request_options=request_options,
354 omit=OMIT,
355 )
356 try:
357 if 200 <= _response.status_code < 300:
358 _data = typing.cast(
359 CreateGuardianEnrollmentTicketResponseContent,
360 parse_obj_as(
361 type_=CreateGuardianEnrollmentTicketResponseContent, # type: ignore
362 object_=_response.json(),
363 ),
364 )
365 return AsyncHttpResponse(response=_response, data=_data)
366 if _response.status_code == 400:
367 raise BadRequestError(
368 headers=dict(_response.headers),
369 body=typing.cast(
370 typing.Any,
371 parse_obj_as(
372 type_=typing.Any, # type: ignore
373 object_=_response.json(),
374 ),
375 ),
376 )
377 if _response.status_code == 401:
378 raise UnauthorizedError(
379 headers=dict(_response.headers),
380 body=typing.cast(
381 typing.Any,
382 parse_obj_as(
383 type_=typing.Any, # type: ignore
384 object_=_response.json(),
385 ),
386 ),
387 )
388 if _response.status_code == 403:
389 raise ForbiddenError(
390 headers=dict(_response.headers),
391 body=typing.cast(
392 typing.Any,
393 parse_obj_as(
394 type_=typing.Any, # type: ignore
395 object_=_response.json(),
396 ),
397 ),
398 )
399 if _response.status_code == 404:
400 raise NotFoundError(
401 headers=dict(_response.headers),
402 body=typing.cast(
403 typing.Any,
404 parse_obj_as(
405 type_=typing.Any, # type: ignore
406 object_=_response.json(),
407 ),
408 ),
409 )
410 _response_json = _response.json()
411 except JSONDecodeError:
412 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
413 except ValidationError as e:
414 raise ParsingError(
415 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
416 )
417 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
418
419 async def get(
420 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
421 ) -> AsyncHttpResponse[GetGuardianEnrollmentResponseContent]:
422 """
423 Retrieve details, such as status and type, for a specific multi-factor authentication enrollment registered to a user account.
424
425 Parameters
426 ----------
427 id : str
428 ID of the enrollment to be retrieve.
429
430 request_options : typing.Optional[RequestOptions]
431 Request-specific configuration.
432
433 Returns
434 -------
435 AsyncHttpResponse[GetGuardianEnrollmentResponseContent]
436 Enrollment successfully retrieved.
437 """
438 _response = await self._client_wrapper.httpx_client.request(
439 f"guardian/enrollments/{encode_path_param(id)}",
440 method="GET",
441 request_options=request_options,
442 )
443 try:
444 if 200 <= _response.status_code < 300:
445 _data = typing.cast(
446 GetGuardianEnrollmentResponseContent,
447 parse_obj_as(
448 type_=GetGuardianEnrollmentResponseContent, # type: ignore
449 object_=_response.json(),
450 ),
451 )
452 return AsyncHttpResponse(response=_response, data=_data)
453 if _response.status_code == 400:
454 raise BadRequestError(
455 headers=dict(_response.headers),
456 body=typing.cast(
457 typing.Any,
458 parse_obj_as(
459 type_=typing.Any, # type: ignore
460 object_=_response.json(),
461 ),
462 ),
463 )
464 if _response.status_code == 401:
465 raise UnauthorizedError(
466 headers=dict(_response.headers),
467 body=typing.cast(
468 typing.Any,
469 parse_obj_as(
470 type_=typing.Any, # type: ignore
471 object_=_response.json(),
472 ),
473 ),
474 )
475 if _response.status_code == 403:
476 raise ForbiddenError(
477 headers=dict(_response.headers),
478 body=typing.cast(
479 typing.Any,
480 parse_obj_as(
481 type_=typing.Any, # type: ignore
482 object_=_response.json(),
483 ),
484 ),
485 )
486 _response_json = _response.json()
487 except JSONDecodeError:
488 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
489 except ValidationError as e:
490 raise ParsingError(
491 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
492 )
493 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
494
495 async def delete(
496 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
497 ) -> AsyncHttpResponse[None]:
498 """
499 Remove a specific multi-factor authentication (MFA) enrollment from a user's account. This allows the user to re-enroll with MFA. For more information, review [Reset User Multi-Factor Authentication and Recovery Codes](https://auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa).
500
501 Parameters
502 ----------
503 id : str
504 ID of the enrollment to be deleted.
505
506 request_options : typing.Optional[RequestOptions]
507 Request-specific configuration.
508
509 Returns
510 -------
511 AsyncHttpResponse[None]
512 """
513 _response = await self._client_wrapper.httpx_client.request(
514 f"guardian/enrollments/{encode_path_param(id)}",
515 method="DELETE",
516 request_options=request_options,
517 )
518 try:
519 if 200 <= _response.status_code < 300:
520 return AsyncHttpResponse(response=_response, data=None)
521 if _response.status_code == 400:
522 raise BadRequestError(
523 headers=dict(_response.headers),
524 body=typing.cast(
525 typing.Any,
526 parse_obj_as(
527 type_=typing.Any, # type: ignore
528 object_=_response.json(),
529 ),
530 ),
531 )
532 if _response.status_code == 401:
533 raise UnauthorizedError(
534 headers=dict(_response.headers),
535 body=typing.cast(
536 typing.Any,
537 parse_obj_as(
538 type_=typing.Any, # type: ignore
539 object_=_response.json(),
540 ),
541 ),
542 )
543 if _response.status_code == 403:
544 raise ForbiddenError(
545 headers=dict(_response.headers),
546 body=typing.cast(
547 typing.Any,
548 parse_obj_as(
549 type_=typing.Any, # type: ignore
550 object_=_response.json(),
551 ),
552 ),
553 )
554 _response_json = _response.json()
555 except JSONDecodeError:
556 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
557 except ValidationError as e:
558 raise ParsingError(
559 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
560 )
561 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)