Debian Codegraph @

src/auth0/management/users/authenticators/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.too_many_requests_error import TooManyRequestsError
16 from ...errors.unauthorized_error import UnauthorizedError
17 from pydantic import ValidationError
18
19
20 class RawAuthenticatorsClient:
21 def __init__(self, *, client_wrapper: SyncClientWrapper):
22 self._client_wrapper = client_wrapper
23
24 def delete_all(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
25 """
26 Remove all authenticators registered to a given user ID, such as OTP, email, phone, and push-notification. This action cannot be undone. For more information, review [Manage Authentication Methods with Management API](https://auth0.com/docs/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authentication-methods-with-management-api).
27
28 Parameters
29 ----------
30 id : str
31 ID of the user to delete.
32
33 request_options : typing.Optional[RequestOptions]
34 Request-specific configuration.
35
36 Returns
37 -------
38 HttpResponse[None]
39 """
40 _response = self._client_wrapper.httpx_client.request(
41 f"users/{encode_path_param(id)}/authenticators",
42 method="DELETE",
43 request_options=request_options,
44 )
45 try:
46 if 200 <= _response.status_code < 300:
47 return HttpResponse(response=_response, data=None)
48 if _response.status_code == 400:
49 raise BadRequestError(
50 headers=dict(_response.headers),
51 body=typing.cast(
52 typing.Any,
53 parse_obj_as(
54 type_=typing.Any, # type: ignore
55 object_=_response.json(),
56 ),
57 ),
58 )
59 if _response.status_code == 401:
60 raise UnauthorizedError(
61 headers=dict(_response.headers),
62 body=typing.cast(
63 typing.Any,
64 parse_obj_as(
65 type_=typing.Any, # type: ignore
66 object_=_response.json(),
67 ),
68 ),
69 )
70 if _response.status_code == 403:
71 raise ForbiddenError(
72 headers=dict(_response.headers),
73 body=typing.cast(
74 typing.Any,
75 parse_obj_as(
76 type_=typing.Any, # type: ignore
77 object_=_response.json(),
78 ),
79 ),
80 )
81 if _response.status_code == 429:
82 raise TooManyRequestsError(
83 headers=dict(_response.headers),
84 body=typing.cast(
85 typing.Any,
86 parse_obj_as(
87 type_=typing.Any, # type: ignore
88 object_=_response.json(),
89 ),
90 ),
91 )
92 _response_json = _response.json()
93 except JSONDecodeError:
94 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
95 except ValidationError as e:
96 raise ParsingError(
97 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
98 )
99 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
100
101
102 class AsyncRawAuthenticatorsClient:
103 def __init__(self, *, client_wrapper: AsyncClientWrapper):
104 self._client_wrapper = client_wrapper
105
106 async def delete_all(
107 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
108 ) -> AsyncHttpResponse[None]:
109 """
110 Remove all authenticators registered to a given user ID, such as OTP, email, phone, and push-notification. This action cannot be undone. For more information, review [Manage Authentication Methods with Management API](https://auth0.com/docs/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authentication-methods-with-management-api).
111
112 Parameters
113 ----------
114 id : str
115 ID of the user to delete.
116
117 request_options : typing.Optional[RequestOptions]
118 Request-specific configuration.
119
120 Returns
121 -------
122 AsyncHttpResponse[None]
123 """
124 _response = await self._client_wrapper.httpx_client.request(
125 f"users/{encode_path_param(id)}/authenticators",
126 method="DELETE",
127 request_options=request_options,
128 )
129 try:
130 if 200 <= _response.status_code < 300:
131 return AsyncHttpResponse(response=_response, data=None)
132 if _response.status_code == 400:
133 raise BadRequestError(
134 headers=dict(_response.headers),
135 body=typing.cast(
136 typing.Any,
137 parse_obj_as(
138 type_=typing.Any, # type: ignore
139 object_=_response.json(),
140 ),
141 ),
142 )
143 if _response.status_code == 401:
144 raise UnauthorizedError(
145 headers=dict(_response.headers),
146 body=typing.cast(
147 typing.Any,
148 parse_obj_as(
149 type_=typing.Any, # type: ignore
150 object_=_response.json(),
151 ),
152 ),
153 )
154 if _response.status_code == 403:
155 raise ForbiddenError(
156 headers=dict(_response.headers),
157 body=typing.cast(
158 typing.Any,
159 parse_obj_as(
160 type_=typing.Any, # type: ignore
161 object_=_response.json(),
162 ),
163 ),
164 )
165 if _response.status_code == 429:
166 raise TooManyRequestsError(
167 headers=dict(_response.headers),
168 body=typing.cast(
169 typing.Any,
170 parse_obj_as(
171 type_=typing.Any, # type: ignore
172 object_=_response.json(),
173 ),
174 ),
175 )
176 _response_json = _response.json()
177 except JSONDecodeError:
178 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
179 except ValidationError as e:
180 raise ParsingError(
181 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
182 )
183 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)