| 1 |
|
| 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.pagination import AsyncPager, SyncPager |
| 11 |
from ...core.parse_error import ParsingError |
| 12 |
from ...core.pydantic_utilities import parse_obj_as |
| 13 |
from ...core.request_options import RequestOptions |
| 14 |
from ...core.serialization import convert_and_respect_annotation_metadata |
| 15 |
from ...errors.bad_request_error import BadRequestError |
| 16 |
from ...errors.conflict_error import ConflictError |
| 17 |
from ...errors.forbidden_error import ForbiddenError |
| 18 |
from ...errors.not_found_error import NotFoundError |
| 19 |
from ...errors.too_many_requests_error import TooManyRequestsError |
| 20 |
from ...errors.unauthorized_error import UnauthorizedError |
| 21 |
from ...types.create_user_authentication_method_response_content import CreateUserAuthenticationMethodResponseContent |
| 22 |
from ...types.created_user_authentication_method_type_enum import CreatedUserAuthenticationMethodTypeEnum |
| 23 |
from ...types.credential_device_type_enum import CredentialDeviceTypeEnum |
| 24 |
from ...types.get_user_authentication_method_response_content import GetUserAuthenticationMethodResponseContent |
| 25 |
from ...types.list_user_authentication_methods_offset_paginated_response_content import ( |
| 26 |
ListUserAuthenticationMethodsOffsetPaginatedResponseContent, |
| 27 |
) |
| 28 |
from ...types.preferred_authentication_method_enum import PreferredAuthenticationMethodEnum |
| 29 |
from ...types.set_user_authentication_method_response_content import SetUserAuthenticationMethodResponseContent |
| 30 |
from ...types.set_user_authentication_methods_request_content import SetUserAuthenticationMethodsRequestContent |
| 31 |
from ...types.update_user_authentication_method_response_content import UpdateUserAuthenticationMethodResponseContent |
| 32 |
from ...types.user_authentication_method import UserAuthenticationMethod |
| 33 |
from pydantic import ValidationError |
| 34 |
|
| 35 |
|
| 36 |
OMIT = typing.cast(typing.Any, ...) |
| 37 |
|
| 38 |
|
| 39 |
class RawAuthenticationMethodsClient: |
| 40 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 41 |
self._client_wrapper = client_wrapper |
| 42 |
|
| 43 |
def list( |
| 44 |
self, |
| 45 |
id: str, |
| 46 |
*, |
| 47 |
page: typing.Optional[int] = 0, |
| 48 |
per_page: typing.Optional[int] = 50, |
| 49 |
include_totals: typing.Optional[bool] = True, |
| 50 |
request_options: typing.Optional[RequestOptions] = None, |
| 51 |
) -> SyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent]: |
| 52 |
""" |
| 53 |
Retrieve detailed list of authentication methods associated with a specified user. |
| 54 |
|
| 55 |
Parameters |
| 56 |
---------- |
| 57 |
id : str |
| 58 |
The ID of the user in question. |
| 59 |
|
| 60 |
page : typing.Optional[int] |
| 61 |
Page index of the results to return. First page is 0. Default is 0. |
| 62 |
|
| 63 |
per_page : typing.Optional[int] |
| 64 |
Number of results per page. Default is 50. |
| 65 |
|
| 66 |
include_totals : typing.Optional[bool] |
| 67 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 68 |
|
| 69 |
request_options : typing.Optional[RequestOptions] |
| 70 |
Request-specific configuration. |
| 71 |
|
| 72 |
Returns |
| 73 |
------- |
| 74 |
SyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent] |
| 75 |
The authentication methods for the user were retrieved. |
| 76 |
""" |
| 77 |
page = page if page is not None else 0 |
| 78 |
|
| 79 |
_response = self._client_wrapper.httpx_client.request( |
| 80 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 81 |
method="GET", |
| 82 |
params={ |
| 83 |
"page": page, |
| 84 |
"per_page": per_page, |
| 85 |
"include_totals": include_totals, |
| 86 |
}, |
| 87 |
request_options=request_options, |
| 88 |
) |
| 89 |
try: |
| 90 |
if 200 <= _response.status_code < 300: |
| 91 |
_parsed_response = typing.cast( |
| 92 |
ListUserAuthenticationMethodsOffsetPaginatedResponseContent, |
| 93 |
parse_obj_as( |
| 94 |
type_=ListUserAuthenticationMethodsOffsetPaginatedResponseContent, |
| 95 |
object_=_response.json(), |
| 96 |
), |
| 97 |
) |
| 98 |
_items = _parsed_response.authenticators |
| 99 |
_has_next = len(_items or []) > 0 |
| 100 |
_get_next = lambda: self.list( |
| 101 |
id, |
| 102 |
page=page + 1, |
| 103 |
per_page=per_page, |
| 104 |
include_totals=include_totals, |
| 105 |
request_options=request_options, |
| 106 |
) |
| 107 |
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 108 |
if _response.status_code == 400: |
| 109 |
raise BadRequestError( |
| 110 |
headers=dict(_response.headers), |
| 111 |
body=typing.cast( |
| 112 |
typing.Any, |
| 113 |
parse_obj_as( |
| 114 |
type_=typing.Any, |
| 115 |
object_=_response.json(), |
| 116 |
), |
| 117 |
), |
| 118 |
) |
| 119 |
if _response.status_code == 401: |
| 120 |
raise UnauthorizedError( |
| 121 |
headers=dict(_response.headers), |
| 122 |
body=typing.cast( |
| 123 |
typing.Any, |
| 124 |
parse_obj_as( |
| 125 |
type_=typing.Any, |
| 126 |
object_=_response.json(), |
| 127 |
), |
| 128 |
), |
| 129 |
) |
| 130 |
if _response.status_code == 403: |
| 131 |
raise ForbiddenError( |
| 132 |
headers=dict(_response.headers), |
| 133 |
body=typing.cast( |
| 134 |
typing.Any, |
| 135 |
parse_obj_as( |
| 136 |
type_=typing.Any, |
| 137 |
object_=_response.json(), |
| 138 |
), |
| 139 |
), |
| 140 |
) |
| 141 |
if _response.status_code == 404: |
| 142 |
raise NotFoundError( |
| 143 |
headers=dict(_response.headers), |
| 144 |
body=typing.cast( |
| 145 |
typing.Any, |
| 146 |
parse_obj_as( |
| 147 |
type_=typing.Any, |
| 148 |
object_=_response.json(), |
| 149 |
), |
| 150 |
), |
| 151 |
) |
| 152 |
if _response.status_code == 429: |
| 153 |
raise TooManyRequestsError( |
| 154 |
headers=dict(_response.headers), |
| 155 |
body=typing.cast( |
| 156 |
typing.Any, |
| 157 |
parse_obj_as( |
| 158 |
type_=typing.Any, |
| 159 |
object_=_response.json(), |
| 160 |
), |
| 161 |
), |
| 162 |
) |
| 163 |
_response_json = _response.json() |
| 164 |
except JSONDecodeError: |
| 165 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 166 |
except ValidationError as e: |
| 167 |
raise ParsingError( |
| 168 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 169 |
) |
| 170 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 171 |
|
| 172 |
def create( |
| 173 |
self, |
| 174 |
id: str, |
| 175 |
*, |
| 176 |
type: CreatedUserAuthenticationMethodTypeEnum, |
| 177 |
name: typing.Optional[str] = OMIT, |
| 178 |
totp_secret: typing.Optional[str] = OMIT, |
| 179 |
phone_number: typing.Optional[str] = OMIT, |
| 180 |
email: typing.Optional[str] = OMIT, |
| 181 |
preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, |
| 182 |
key_id: typing.Optional[str] = OMIT, |
| 183 |
public_key: typing.Optional[str] = OMIT, |
| 184 |
aaguid: typing.Optional[str] = OMIT, |
| 185 |
relying_party_identifier: typing.Optional[str] = OMIT, |
| 186 |
credential_device_type: typing.Optional[CredentialDeviceTypeEnum] = OMIT, |
| 187 |
credential_backed_up: typing.Optional[bool] = OMIT, |
| 188 |
identity_user_id: typing.Optional[str] = OMIT, |
| 189 |
user_agent: typing.Optional[str] = OMIT, |
| 190 |
user_handle: typing.Optional[str] = OMIT, |
| 191 |
transports: typing.Optional[typing.Sequence[str]] = OMIT, |
| 192 |
request_options: typing.Optional[RequestOptions] = None, |
| 193 |
) -> HttpResponse[CreateUserAuthenticationMethodResponseContent]: |
| 194 |
""" |
| 195 |
Create an authentication method. Authentication methods created via this endpoint will be auto confirmed and should already have verification completed. |
| 196 |
|
| 197 |
Parameters |
| 198 |
---------- |
| 199 |
id : str |
| 200 |
The ID of the user to whom the new authentication method will be assigned. |
| 201 |
|
| 202 |
type : CreatedUserAuthenticationMethodTypeEnum |
| 203 |
|
| 204 |
name : typing.Optional[str] |
| 205 |
A human-readable label to identify the authentication method. |
| 206 |
|
| 207 |
totp_secret : typing.Optional[str] |
| 208 |
Base32 encoded secret for TOTP generation. |
| 209 |
|
| 210 |
phone_number : typing.Optional[str] |
| 211 |
Applies to phone authentication methods only. The destination phone number used to send verification codes via text and voice. |
| 212 |
|
| 213 |
email : typing.Optional[str] |
| 214 |
Applies to email authentication methods only. The email address used to send verification messages. |
| 215 |
|
| 216 |
preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] |
| 217 |
|
| 218 |
key_id : typing.Optional[str] |
| 219 |
Applies to webauthn/passkey authentication methods only. The id of the credential. |
| 220 |
|
| 221 |
public_key : typing.Optional[str] |
| 222 |
Applies to webauthn/passkey authentication methods only. The public key, which is encoded as base64. |
| 223 |
|
| 224 |
aaguid : typing.Optional[str] |
| 225 |
Applies to passkeys only. Authenticator Attestation Globally Unique Identifier |
| 226 |
|
| 227 |
relying_party_identifier : typing.Optional[str] |
| 228 |
Applies to webauthn authentication methods only. The relying party identifier. |
| 229 |
|
| 230 |
credential_device_type : typing.Optional[CredentialDeviceTypeEnum] |
| 231 |
|
| 232 |
credential_backed_up : typing.Optional[bool] |
| 233 |
Applies to passkeys only. Whether the credential was backed up. |
| 234 |
|
| 235 |
identity_user_id : typing.Optional[str] |
| 236 |
Applies to passkeys only. The ID of the user identity linked with the authentication method. |
| 237 |
|
| 238 |
user_agent : typing.Optional[str] |
| 239 |
Applies to passkeys only. The user-agent of the browser used to create the passkey. |
| 240 |
|
| 241 |
user_handle : typing.Optional[str] |
| 242 |
Applies to passkeys only. The user handle of the user identity. |
| 243 |
|
| 244 |
transports : typing.Optional[typing.Sequence[str]] |
| 245 |
Applies to passkeys only. The transports used by clients to communicate with the authenticator. |
| 246 |
|
| 247 |
request_options : typing.Optional[RequestOptions] |
| 248 |
Request-specific configuration. |
| 249 |
|
| 250 |
Returns |
| 251 |
------- |
| 252 |
HttpResponse[CreateUserAuthenticationMethodResponseContent] |
| 253 |
Authentication method created. |
| 254 |
""" |
| 255 |
_response = self._client_wrapper.httpx_client.request( |
| 256 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 257 |
method="POST", |
| 258 |
json={ |
| 259 |
"type": type, |
| 260 |
"name": name, |
| 261 |
"totp_secret": totp_secret, |
| 262 |
"phone_number": phone_number, |
| 263 |
"email": email, |
| 264 |
"preferred_authentication_method": preferred_authentication_method, |
| 265 |
"key_id": key_id, |
| 266 |
"public_key": public_key, |
| 267 |
"aaguid": aaguid, |
| 268 |
"relying_party_identifier": relying_party_identifier, |
| 269 |
"credential_device_type": credential_device_type, |
| 270 |
"credential_backed_up": credential_backed_up, |
| 271 |
"identity_user_id": identity_user_id, |
| 272 |
"user_agent": user_agent, |
| 273 |
"user_handle": user_handle, |
| 274 |
"transports": transports, |
| 275 |
}, |
| 276 |
headers={ |
| 277 |
"content-type": "application/json", |
| 278 |
}, |
| 279 |
request_options=request_options, |
| 280 |
omit=OMIT, |
| 281 |
) |
| 282 |
try: |
| 283 |
if 200 <= _response.status_code < 300: |
| 284 |
_data = typing.cast( |
| 285 |
CreateUserAuthenticationMethodResponseContent, |
| 286 |
parse_obj_as( |
| 287 |
type_=CreateUserAuthenticationMethodResponseContent, |
| 288 |
object_=_response.json(), |
| 289 |
), |
| 290 |
) |
| 291 |
return HttpResponse(response=_response, data=_data) |
| 292 |
if _response.status_code == 400: |
| 293 |
raise BadRequestError( |
| 294 |
headers=dict(_response.headers), |
| 295 |
body=typing.cast( |
| 296 |
typing.Any, |
| 297 |
parse_obj_as( |
| 298 |
type_=typing.Any, |
| 299 |
object_=_response.json(), |
| 300 |
), |
| 301 |
), |
| 302 |
) |
| 303 |
if _response.status_code == 401: |
| 304 |
raise UnauthorizedError( |
| 305 |
headers=dict(_response.headers), |
| 306 |
body=typing.cast( |
| 307 |
typing.Any, |
| 308 |
parse_obj_as( |
| 309 |
type_=typing.Any, |
| 310 |
object_=_response.json(), |
| 311 |
), |
| 312 |
), |
| 313 |
) |
| 314 |
if _response.status_code == 403: |
| 315 |
raise ForbiddenError( |
| 316 |
headers=dict(_response.headers), |
| 317 |
body=typing.cast( |
| 318 |
typing.Any, |
| 319 |
parse_obj_as( |
| 320 |
type_=typing.Any, |
| 321 |
object_=_response.json(), |
| 322 |
), |
| 323 |
), |
| 324 |
) |
| 325 |
if _response.status_code == 404: |
| 326 |
raise NotFoundError( |
| 327 |
headers=dict(_response.headers), |
| 328 |
body=typing.cast( |
| 329 |
typing.Any, |
| 330 |
parse_obj_as( |
| 331 |
type_=typing.Any, |
| 332 |
object_=_response.json(), |
| 333 |
), |
| 334 |
), |
| 335 |
) |
| 336 |
if _response.status_code == 409: |
| 337 |
raise ConflictError( |
| 338 |
headers=dict(_response.headers), |
| 339 |
body=typing.cast( |
| 340 |
typing.Any, |
| 341 |
parse_obj_as( |
| 342 |
type_=typing.Any, |
| 343 |
object_=_response.json(), |
| 344 |
), |
| 345 |
), |
| 346 |
) |
| 347 |
if _response.status_code == 429: |
| 348 |
raise TooManyRequestsError( |
| 349 |
headers=dict(_response.headers), |
| 350 |
body=typing.cast( |
| 351 |
typing.Any, |
| 352 |
parse_obj_as( |
| 353 |
type_=typing.Any, |
| 354 |
object_=_response.json(), |
| 355 |
), |
| 356 |
), |
| 357 |
) |
| 358 |
_response_json = _response.json() |
| 359 |
except JSONDecodeError: |
| 360 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 361 |
except ValidationError as e: |
| 362 |
raise ParsingError( |
| 363 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 364 |
) |
| 365 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 366 |
|
| 367 |
def set( |
| 368 |
self, |
| 369 |
id: str, |
| 370 |
*, |
| 371 |
request: SetUserAuthenticationMethodsRequestContent, |
| 372 |
request_options: typing.Optional[RequestOptions] = None, |
| 373 |
) -> HttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]]: |
| 374 |
""" |
| 375 |
Replace the specified user <a href="https://auth0.com/docs/secure/multi-factor-authentication/multi-factor-authentication-factors"> authentication methods</a> with supplied values. |
| 376 |
|
| 377 |
<b>Note</b>: Authentication methods supplied through this action do not iterate on existing methods. Instead, any methods passed will overwrite the user’s existing settings. |
| 378 |
|
| 379 |
Parameters |
| 380 |
---------- |
| 381 |
id : str |
| 382 |
The ID of the user in question. |
| 383 |
|
| 384 |
request : SetUserAuthenticationMethodsRequestContent |
| 385 |
|
| 386 |
request_options : typing.Optional[RequestOptions] |
| 387 |
Request-specific configuration. |
| 388 |
|
| 389 |
Returns |
| 390 |
------- |
| 391 |
HttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]] |
| 392 |
All authentication methods successfully updated. |
| 393 |
""" |
| 394 |
_response = self._client_wrapper.httpx_client.request( |
| 395 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 396 |
method="PUT", |
| 397 |
json=convert_and_respect_annotation_metadata( |
| 398 |
object_=request, annotation=SetUserAuthenticationMethodsRequestContent, direction="write" |
| 399 |
), |
| 400 |
request_options=request_options, |
| 401 |
omit=OMIT, |
| 402 |
) |
| 403 |
try: |
| 404 |
if 200 <= _response.status_code < 300: |
| 405 |
_data = typing.cast( |
| 406 |
typing.List[SetUserAuthenticationMethodResponseContent], |
| 407 |
parse_obj_as( |
| 408 |
type_=typing.List[SetUserAuthenticationMethodResponseContent], |
| 409 |
object_=_response.json(), |
| 410 |
), |
| 411 |
) |
| 412 |
return HttpResponse(response=_response, data=_data) |
| 413 |
if _response.status_code == 400: |
| 414 |
raise BadRequestError( |
| 415 |
headers=dict(_response.headers), |
| 416 |
body=typing.cast( |
| 417 |
typing.Any, |
| 418 |
parse_obj_as( |
| 419 |
type_=typing.Any, |
| 420 |
object_=_response.json(), |
| 421 |
), |
| 422 |
), |
| 423 |
) |
| 424 |
if _response.status_code == 401: |
| 425 |
raise UnauthorizedError( |
| 426 |
headers=dict(_response.headers), |
| 427 |
body=typing.cast( |
| 428 |
typing.Any, |
| 429 |
parse_obj_as( |
| 430 |
type_=typing.Any, |
| 431 |
object_=_response.json(), |
| 432 |
), |
| 433 |
), |
| 434 |
) |
| 435 |
if _response.status_code == 403: |
| 436 |
raise ForbiddenError( |
| 437 |
headers=dict(_response.headers), |
| 438 |
body=typing.cast( |
| 439 |
typing.Any, |
| 440 |
parse_obj_as( |
| 441 |
type_=typing.Any, |
| 442 |
object_=_response.json(), |
| 443 |
), |
| 444 |
), |
| 445 |
) |
| 446 |
if _response.status_code == 409: |
| 447 |
raise ConflictError( |
| 448 |
headers=dict(_response.headers), |
| 449 |
body=typing.cast( |
| 450 |
typing.Any, |
| 451 |
parse_obj_as( |
| 452 |
type_=typing.Any, |
| 453 |
object_=_response.json(), |
| 454 |
), |
| 455 |
), |
| 456 |
) |
| 457 |
if _response.status_code == 429: |
| 458 |
raise TooManyRequestsError( |
| 459 |
headers=dict(_response.headers), |
| 460 |
body=typing.cast( |
| 461 |
typing.Any, |
| 462 |
parse_obj_as( |
| 463 |
type_=typing.Any, |
| 464 |
object_=_response.json(), |
| 465 |
), |
| 466 |
), |
| 467 |
) |
| 468 |
_response_json = _response.json() |
| 469 |
except JSONDecodeError: |
| 470 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 471 |
except ValidationError as e: |
| 472 |
raise ParsingError( |
| 473 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 474 |
) |
| 475 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 476 |
|
| 477 |
def delete_all(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]: |
| 478 |
""" |
| 479 |
Remove all authentication methods (i.e., enrolled MFA factors) from the specified user account. This action cannot be undone. |
| 480 |
|
| 481 |
Parameters |
| 482 |
---------- |
| 483 |
id : str |
| 484 |
The ID of the user in question. |
| 485 |
|
| 486 |
request_options : typing.Optional[RequestOptions] |
| 487 |
Request-specific configuration. |
| 488 |
|
| 489 |
Returns |
| 490 |
------- |
| 491 |
HttpResponse[None] |
| 492 |
""" |
| 493 |
_response = self._client_wrapper.httpx_client.request( |
| 494 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 495 |
method="DELETE", |
| 496 |
request_options=request_options, |
| 497 |
) |
| 498 |
try: |
| 499 |
if 200 <= _response.status_code < 300: |
| 500 |
return HttpResponse(response=_response, data=None) |
| 501 |
if _response.status_code == 400: |
| 502 |
raise BadRequestError( |
| 503 |
headers=dict(_response.headers), |
| 504 |
body=typing.cast( |
| 505 |
typing.Any, |
| 506 |
parse_obj_as( |
| 507 |
type_=typing.Any, |
| 508 |
object_=_response.json(), |
| 509 |
), |
| 510 |
), |
| 511 |
) |
| 512 |
if _response.status_code == 401: |
| 513 |
raise UnauthorizedError( |
| 514 |
headers=dict(_response.headers), |
| 515 |
body=typing.cast( |
| 516 |
typing.Any, |
| 517 |
parse_obj_as( |
| 518 |
type_=typing.Any, |
| 519 |
object_=_response.json(), |
| 520 |
), |
| 521 |
), |
| 522 |
) |
| 523 |
if _response.status_code == 403: |
| 524 |
raise ForbiddenError( |
| 525 |
headers=dict(_response.headers), |
| 526 |
body=typing.cast( |
| 527 |
typing.Any, |
| 528 |
parse_obj_as( |
| 529 |
type_=typing.Any, |
| 530 |
object_=_response.json(), |
| 531 |
), |
| 532 |
), |
| 533 |
) |
| 534 |
if _response.status_code == 429: |
| 535 |
raise TooManyRequestsError( |
| 536 |
headers=dict(_response.headers), |
| 537 |
body=typing.cast( |
| 538 |
typing.Any, |
| 539 |
parse_obj_as( |
| 540 |
type_=typing.Any, |
| 541 |
object_=_response.json(), |
| 542 |
), |
| 543 |
), |
| 544 |
) |
| 545 |
_response_json = _response.json() |
| 546 |
except JSONDecodeError: |
| 547 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 548 |
except ValidationError as e: |
| 549 |
raise ParsingError( |
| 550 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 551 |
) |
| 552 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 553 |
|
| 554 |
def get( |
| 555 |
self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 556 |
) -> HttpResponse[GetUserAuthenticationMethodResponseContent]: |
| 557 |
""" |
| 558 |
Parameters |
| 559 |
---------- |
| 560 |
id : str |
| 561 |
The ID of the user in question. |
| 562 |
|
| 563 |
authentication_method_id : str |
| 564 |
The ID of the authentication methods in question. |
| 565 |
|
| 566 |
request_options : typing.Optional[RequestOptions] |
| 567 |
Request-specific configuration. |
| 568 |
|
| 569 |
Returns |
| 570 |
------- |
| 571 |
HttpResponse[GetUserAuthenticationMethodResponseContent] |
| 572 |
Authentication method retrieved. |
| 573 |
""" |
| 574 |
_response = self._client_wrapper.httpx_client.request( |
| 575 |
f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", |
| 576 |
method="GET", |
| 577 |
request_options=request_options, |
| 578 |
) |
| 579 |
try: |
| 580 |
if 200 <= _response.status_code < 300: |
| 581 |
_data = typing.cast( |
| 582 |
GetUserAuthenticationMethodResponseContent, |
| 583 |
parse_obj_as( |
| 584 |
type_=GetUserAuthenticationMethodResponseContent, |
| 585 |
object_=_response.json(), |
| 586 |
), |
| 587 |
) |
| 588 |
return HttpResponse(response=_response, data=_data) |
| 589 |
if _response.status_code == 400: |
| 590 |
raise BadRequestError( |
| 591 |
headers=dict(_response.headers), |
| 592 |
body=typing.cast( |
| 593 |
typing.Any, |
| 594 |
parse_obj_as( |
| 595 |
type_=typing.Any, |
| 596 |
object_=_response.json(), |
| 597 |
), |
| 598 |
), |
| 599 |
) |
| 600 |
if _response.status_code == 401: |
| 601 |
raise UnauthorizedError( |
| 602 |
headers=dict(_response.headers), |
| 603 |
body=typing.cast( |
| 604 |
typing.Any, |
| 605 |
parse_obj_as( |
| 606 |
type_=typing.Any, |
| 607 |
object_=_response.json(), |
| 608 |
), |
| 609 |
), |
| 610 |
) |
| 611 |
if _response.status_code == 403: |
| 612 |
raise ForbiddenError( |
| 613 |
headers=dict(_response.headers), |
| 614 |
body=typing.cast( |
| 615 |
typing.Any, |
| 616 |
parse_obj_as( |
| 617 |
type_=typing.Any, |
| 618 |
object_=_response.json(), |
| 619 |
), |
| 620 |
), |
| 621 |
) |
| 622 |
if _response.status_code == 404: |
| 623 |
raise NotFoundError( |
| 624 |
headers=dict(_response.headers), |
| 625 |
body=typing.cast( |
| 626 |
typing.Any, |
| 627 |
parse_obj_as( |
| 628 |
type_=typing.Any, |
| 629 |
object_=_response.json(), |
| 630 |
), |
| 631 |
), |
| 632 |
) |
| 633 |
if _response.status_code == 429: |
| 634 |
raise TooManyRequestsError( |
| 635 |
headers=dict(_response.headers), |
| 636 |
body=typing.cast( |
| 637 |
typing.Any, |
| 638 |
parse_obj_as( |
| 639 |
type_=typing.Any, |
| 640 |
object_=_response.json(), |
| 641 |
), |
| 642 |
), |
| 643 |
) |
| 644 |
_response_json = _response.json() |
| 645 |
except JSONDecodeError: |
| 646 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 647 |
except ValidationError as e: |
| 648 |
raise ParsingError( |
| 649 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 650 |
) |
| 651 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 652 |
|
| 653 |
def delete( |
| 654 |
self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 655 |
) -> HttpResponse[None]: |
| 656 |
""" |
| 657 |
Remove the authentication method with the given ID from the specified user. For more information, review <a href="https://auth0.com/docs/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authentication-methods-with-management-api">Manage Authentication Methods with Management API</a>. |
| 658 |
|
| 659 |
Parameters |
| 660 |
---------- |
| 661 |
id : str |
| 662 |
The ID of the user in question. |
| 663 |
|
| 664 |
authentication_method_id : str |
| 665 |
The ID of the authentication method to delete. |
| 666 |
|
| 667 |
request_options : typing.Optional[RequestOptions] |
| 668 |
Request-specific configuration. |
| 669 |
|
| 670 |
Returns |
| 671 |
------- |
| 672 |
HttpResponse[None] |
| 673 |
""" |
| 674 |
_response = self._client_wrapper.httpx_client.request( |
| 675 |
f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", |
| 676 |
method="DELETE", |
| 677 |
request_options=request_options, |
| 678 |
) |
| 679 |
try: |
| 680 |
if 200 <= _response.status_code < 300: |
| 681 |
return HttpResponse(response=_response, data=None) |
| 682 |
if _response.status_code == 400: |
| 683 |
raise BadRequestError( |
| 684 |
headers=dict(_response.headers), |
| 685 |
body=typing.cast( |
| 686 |
typing.Any, |
| 687 |
parse_obj_as( |
| 688 |
type_=typing.Any, |
| 689 |
object_=_response.json(), |
| 690 |
), |
| 691 |
), |
| 692 |
) |
| 693 |
if _response.status_code == 401: |
| 694 |
raise UnauthorizedError( |
| 695 |
headers=dict(_response.headers), |
| 696 |
body=typing.cast( |
| 697 |
typing.Any, |
| 698 |
parse_obj_as( |
| 699 |
type_=typing.Any, |
| 700 |
object_=_response.json(), |
| 701 |
), |
| 702 |
), |
| 703 |
) |
| 704 |
if _response.status_code == 403: |
| 705 |
raise ForbiddenError( |
| 706 |
headers=dict(_response.headers), |
| 707 |
body=typing.cast( |
| 708 |
typing.Any, |
| 709 |
parse_obj_as( |
| 710 |
type_=typing.Any, |
| 711 |
object_=_response.json(), |
| 712 |
), |
| 713 |
), |
| 714 |
) |
| 715 |
if _response.status_code == 404: |
| 716 |
raise NotFoundError( |
| 717 |
headers=dict(_response.headers), |
| 718 |
body=typing.cast( |
| 719 |
typing.Any, |
| 720 |
parse_obj_as( |
| 721 |
type_=typing.Any, |
| 722 |
object_=_response.json(), |
| 723 |
), |
| 724 |
), |
| 725 |
) |
| 726 |
if _response.status_code == 429: |
| 727 |
raise TooManyRequestsError( |
| 728 |
headers=dict(_response.headers), |
| 729 |
body=typing.cast( |
| 730 |
typing.Any, |
| 731 |
parse_obj_as( |
| 732 |
type_=typing.Any, |
| 733 |
object_=_response.json(), |
| 734 |
), |
| 735 |
), |
| 736 |
) |
| 737 |
_response_json = _response.json() |
| 738 |
except JSONDecodeError: |
| 739 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 740 |
except ValidationError as e: |
| 741 |
raise ParsingError( |
| 742 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 743 |
) |
| 744 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 745 |
|
| 746 |
def update( |
| 747 |
self, |
| 748 |
id: str, |
| 749 |
authentication_method_id: str, |
| 750 |
*, |
| 751 |
name: typing.Optional[str] = OMIT, |
| 752 |
preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, |
| 753 |
request_options: typing.Optional[RequestOptions] = None, |
| 754 |
) -> HttpResponse[UpdateUserAuthenticationMethodResponseContent]: |
| 755 |
""" |
| 756 |
Modify the authentication method with the given ID from the specified user. For more information, review <a href="https://auth0.com/docs/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authentication-methods-with-management-api">Manage Authentication Methods with Management API</a>. |
| 757 |
|
| 758 |
Parameters |
| 759 |
---------- |
| 760 |
id : str |
| 761 |
The ID of the user in question. |
| 762 |
|
| 763 |
authentication_method_id : str |
| 764 |
The ID of the authentication method to update. |
| 765 |
|
| 766 |
name : typing.Optional[str] |
| 767 |
A human-readable label to identify the authentication method. |
| 768 |
|
| 769 |
preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] |
| 770 |
Preferred phone authentication method |
| 771 |
|
| 772 |
request_options : typing.Optional[RequestOptions] |
| 773 |
Request-specific configuration. |
| 774 |
|
| 775 |
Returns |
| 776 |
------- |
| 777 |
HttpResponse[UpdateUserAuthenticationMethodResponseContent] |
| 778 |
Authentication method updated. |
| 779 |
""" |
| 780 |
_response = self._client_wrapper.httpx_client.request( |
| 781 |
f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", |
| 782 |
method="PATCH", |
| 783 |
json={ |
| 784 |
"name": name, |
| 785 |
"preferred_authentication_method": preferred_authentication_method, |
| 786 |
}, |
| 787 |
headers={ |
| 788 |
"content-type": "application/json", |
| 789 |
}, |
| 790 |
request_options=request_options, |
| 791 |
omit=OMIT, |
| 792 |
) |
| 793 |
try: |
| 794 |
if 200 <= _response.status_code < 300: |
| 795 |
_data = typing.cast( |
| 796 |
UpdateUserAuthenticationMethodResponseContent, |
| 797 |
parse_obj_as( |
| 798 |
type_=UpdateUserAuthenticationMethodResponseContent, |
| 799 |
object_=_response.json(), |
| 800 |
), |
| 801 |
) |
| 802 |
return HttpResponse(response=_response, data=_data) |
| 803 |
if _response.status_code == 400: |
| 804 |
raise BadRequestError( |
| 805 |
headers=dict(_response.headers), |
| 806 |
body=typing.cast( |
| 807 |
typing.Any, |
| 808 |
parse_obj_as( |
| 809 |
type_=typing.Any, |
| 810 |
object_=_response.json(), |
| 811 |
), |
| 812 |
), |
| 813 |
) |
| 814 |
if _response.status_code == 401: |
| 815 |
raise UnauthorizedError( |
| 816 |
headers=dict(_response.headers), |
| 817 |
body=typing.cast( |
| 818 |
typing.Any, |
| 819 |
parse_obj_as( |
| 820 |
type_=typing.Any, |
| 821 |
object_=_response.json(), |
| 822 |
), |
| 823 |
), |
| 824 |
) |
| 825 |
if _response.status_code == 403: |
| 826 |
raise ForbiddenError( |
| 827 |
headers=dict(_response.headers), |
| 828 |
body=typing.cast( |
| 829 |
typing.Any, |
| 830 |
parse_obj_as( |
| 831 |
type_=typing.Any, |
| 832 |
object_=_response.json(), |
| 833 |
), |
| 834 |
), |
| 835 |
) |
| 836 |
if _response.status_code == 404: |
| 837 |
raise NotFoundError( |
| 838 |
headers=dict(_response.headers), |
| 839 |
body=typing.cast( |
| 840 |
typing.Any, |
| 841 |
parse_obj_as( |
| 842 |
type_=typing.Any, |
| 843 |
object_=_response.json(), |
| 844 |
), |
| 845 |
), |
| 846 |
) |
| 847 |
if _response.status_code == 429: |
| 848 |
raise TooManyRequestsError( |
| 849 |
headers=dict(_response.headers), |
| 850 |
body=typing.cast( |
| 851 |
typing.Any, |
| 852 |
parse_obj_as( |
| 853 |
type_=typing.Any, |
| 854 |
object_=_response.json(), |
| 855 |
), |
| 856 |
), |
| 857 |
) |
| 858 |
_response_json = _response.json() |
| 859 |
except JSONDecodeError: |
| 860 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 861 |
except ValidationError as e: |
| 862 |
raise ParsingError( |
| 863 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 864 |
) |
| 865 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 866 |
|
| 867 |
|
| 868 |
class AsyncRawAuthenticationMethodsClient: |
| 869 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 870 |
self._client_wrapper = client_wrapper |
| 871 |
|
| 872 |
async def list( |
| 873 |
self, |
| 874 |
id: str, |
| 875 |
*, |
| 876 |
page: typing.Optional[int] = 0, |
| 877 |
per_page: typing.Optional[int] = 50, |
| 878 |
include_totals: typing.Optional[bool] = True, |
| 879 |
request_options: typing.Optional[RequestOptions] = None, |
| 880 |
) -> AsyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent]: |
| 881 |
""" |
| 882 |
Retrieve detailed list of authentication methods associated with a specified user. |
| 883 |
|
| 884 |
Parameters |
| 885 |
---------- |
| 886 |
id : str |
| 887 |
The ID of the user in question. |
| 888 |
|
| 889 |
page : typing.Optional[int] |
| 890 |
Page index of the results to return. First page is 0. Default is 0. |
| 891 |
|
| 892 |
per_page : typing.Optional[int] |
| 893 |
Number of results per page. Default is 50. |
| 894 |
|
| 895 |
include_totals : typing.Optional[bool] |
| 896 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 897 |
|
| 898 |
request_options : typing.Optional[RequestOptions] |
| 899 |
Request-specific configuration. |
| 900 |
|
| 901 |
Returns |
| 902 |
------- |
| 903 |
AsyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent] |
| 904 |
The authentication methods for the user were retrieved. |
| 905 |
""" |
| 906 |
page = page if page is not None else 0 |
| 907 |
|
| 908 |
_response = await self._client_wrapper.httpx_client.request( |
| 909 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 910 |
method="GET", |
| 911 |
params={ |
| 912 |
"page": page, |
| 913 |
"per_page": per_page, |
| 914 |
"include_totals": include_totals, |
| 915 |
}, |
| 916 |
request_options=request_options, |
| 917 |
) |
| 918 |
try: |
| 919 |
if 200 <= _response.status_code < 300: |
| 920 |
_parsed_response = typing.cast( |
| 921 |
ListUserAuthenticationMethodsOffsetPaginatedResponseContent, |
| 922 |
parse_obj_as( |
| 923 |
type_=ListUserAuthenticationMethodsOffsetPaginatedResponseContent, |
| 924 |
object_=_response.json(), |
| 925 |
), |
| 926 |
) |
| 927 |
_items = _parsed_response.authenticators |
| 928 |
_has_next = len(_items or []) > 0 |
| 929 |
|
| 930 |
async def _get_next(): |
| 931 |
return await self.list( |
| 932 |
id, |
| 933 |
page=page + 1, |
| 934 |
per_page=per_page, |
| 935 |
include_totals=include_totals, |
| 936 |
request_options=request_options, |
| 937 |
) |
| 938 |
|
| 939 |
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 940 |
if _response.status_code == 400: |
| 941 |
raise BadRequestError( |
| 942 |
headers=dict(_response.headers), |
| 943 |
body=typing.cast( |
| 944 |
typing.Any, |
| 945 |
parse_obj_as( |
| 946 |
type_=typing.Any, |
| 947 |
object_=_response.json(), |
| 948 |
), |
| 949 |
), |
| 950 |
) |
| 951 |
if _response.status_code == 401: |
| 952 |
raise UnauthorizedError( |
| 953 |
headers=dict(_response.headers), |
| 954 |
body=typing.cast( |
| 955 |
typing.Any, |
| 956 |
parse_obj_as( |
| 957 |
type_=typing.Any, |
| 958 |
object_=_response.json(), |
| 959 |
), |
| 960 |
), |
| 961 |
) |
| 962 |
if _response.status_code == 403: |
| 963 |
raise ForbiddenError( |
| 964 |
headers=dict(_response.headers), |
| 965 |
body=typing.cast( |
| 966 |
typing.Any, |
| 967 |
parse_obj_as( |
| 968 |
type_=typing.Any, |
| 969 |
object_=_response.json(), |
| 970 |
), |
| 971 |
), |
| 972 |
) |
| 973 |
if _response.status_code == 404: |
| 974 |
raise NotFoundError( |
| 975 |
headers=dict(_response.headers), |
| 976 |
body=typing.cast( |
| 977 |
typing.Any, |
| 978 |
parse_obj_as( |
| 979 |
type_=typing.Any, |
| 980 |
object_=_response.json(), |
| 981 |
), |
| 982 |
), |
| 983 |
) |
| 984 |
if _response.status_code == 429: |
| 985 |
raise TooManyRequestsError( |
| 986 |
headers=dict(_response.headers), |
| 987 |
body=typing.cast( |
| 988 |
typing.Any, |
| 989 |
parse_obj_as( |
| 990 |
type_=typing.Any, |
| 991 |
object_=_response.json(), |
| 992 |
), |
| 993 |
), |
| 994 |
) |
| 995 |
_response_json = _response.json() |
| 996 |
except JSONDecodeError: |
| 997 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 998 |
except ValidationError as e: |
| 999 |
raise ParsingError( |
| 1000 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1001 |
) |
| 1002 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1003 |
|
| 1004 |
async def create( |
| 1005 |
self, |
| 1006 |
id: str, |
| 1007 |
*, |
| 1008 |
type: CreatedUserAuthenticationMethodTypeEnum, |
| 1009 |
name: typing.Optional[str] = OMIT, |
| 1010 |
totp_secret: typing.Optional[str] = OMIT, |
| 1011 |
phone_number: typing.Optional[str] = OMIT, |
| 1012 |
email: typing.Optional[str] = OMIT, |
| 1013 |
preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, |
| 1014 |
key_id: typing.Optional[str] = OMIT, |
| 1015 |
public_key: typing.Optional[str] = OMIT, |
| 1016 |
aaguid: typing.Optional[str] = OMIT, |
| 1017 |
relying_party_identifier: typing.Optional[str] = OMIT, |
| 1018 |
credential_device_type: typing.Optional[CredentialDeviceTypeEnum] = OMIT, |
| 1019 |
credential_backed_up: typing.Optional[bool] = OMIT, |
| 1020 |
identity_user_id: typing.Optional[str] = OMIT, |
| 1021 |
user_agent: typing.Optional[str] = OMIT, |
| 1022 |
user_handle: typing.Optional[str] = OMIT, |
| 1023 |
transports: typing.Optional[typing.Sequence[str]] = OMIT, |
| 1024 |
request_options: typing.Optional[RequestOptions] = None, |
| 1025 |
) -> AsyncHttpResponse[CreateUserAuthenticationMethodResponseContent]: |
| 1026 |
""" |
| 1027 |
Create an authentication method. Authentication methods created via this endpoint will be auto confirmed and should already have verification completed. |
| 1028 |
|
| 1029 |
Parameters |
| 1030 |
---------- |
| 1031 |
id : str |
| 1032 |
The ID of the user to whom the new authentication method will be assigned. |
| 1033 |
|
| 1034 |
type : CreatedUserAuthenticationMethodTypeEnum |
| 1035 |
|
| 1036 |
name : typing.Optional[str] |
| 1037 |
A human-readable label to identify the authentication method. |
| 1038 |
|
| 1039 |
totp_secret : typing.Optional[str] |
| 1040 |
Base32 encoded secret for TOTP generation. |
| 1041 |
|
| 1042 |
phone_number : typing.Optional[str] |
| 1043 |
Applies to phone authentication methods only. The destination phone number used to send verification codes via text and voice. |
| 1044 |
|
| 1045 |
email : typing.Optional[str] |
| 1046 |
Applies to email authentication methods only. The email address used to send verification messages. |
| 1047 |
|
| 1048 |
preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] |
| 1049 |
|
| 1050 |
key_id : typing.Optional[str] |
| 1051 |
Applies to webauthn/passkey authentication methods only. The id of the credential. |
| 1052 |
|
| 1053 |
public_key : typing.Optional[str] |
| 1054 |
Applies to webauthn/passkey authentication methods only. The public key, which is encoded as base64. |
| 1055 |
|
| 1056 |
aaguid : typing.Optional[str] |
| 1057 |
Applies to passkeys only. Authenticator Attestation Globally Unique Identifier |
| 1058 |
|
| 1059 |
relying_party_identifier : typing.Optional[str] |
| 1060 |
Applies to webauthn authentication methods only. The relying party identifier. |
| 1061 |
|
| 1062 |
credential_device_type : typing.Optional[CredentialDeviceTypeEnum] |
| 1063 |
|
| 1064 |
credential_backed_up : typing.Optional[bool] |
| 1065 |
Applies to passkeys only. Whether the credential was backed up. |
| 1066 |
|
| 1067 |
identity_user_id : typing.Optional[str] |
| 1068 |
Applies to passkeys only. The ID of the user identity linked with the authentication method. |
| 1069 |
|
| 1070 |
user_agent : typing.Optional[str] |
| 1071 |
Applies to passkeys only. The user-agent of the browser used to create the passkey. |
| 1072 |
|
| 1073 |
user_handle : typing.Optional[str] |
| 1074 |
Applies to passkeys only. The user handle of the user identity. |
| 1075 |
|
| 1076 |
transports : typing.Optional[typing.Sequence[str]] |
| 1077 |
Applies to passkeys only. The transports used by clients to communicate with the authenticator. |
| 1078 |
|
| 1079 |
request_options : typing.Optional[RequestOptions] |
| 1080 |
Request-specific configuration. |
| 1081 |
|
| 1082 |
Returns |
| 1083 |
------- |
| 1084 |
AsyncHttpResponse[CreateUserAuthenticationMethodResponseContent] |
| 1085 |
Authentication method created. |
| 1086 |
""" |
| 1087 |
_response = await self._client_wrapper.httpx_client.request( |
| 1088 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 1089 |
method="POST", |
| 1090 |
json={ |
| 1091 |
"type": type, |
| 1092 |
"name": name, |
| 1093 |
"totp_secret": totp_secret, |
| 1094 |
"phone_number": phone_number, |
| 1095 |
"email": email, |
| 1096 |
"preferred_authentication_method": preferred_authentication_method, |
| 1097 |
"key_id": key_id, |
| 1098 |
"public_key": public_key, |
| 1099 |
"aaguid": aaguid, |
| 1100 |
"relying_party_identifier": relying_party_identifier, |
| 1101 |
"credential_device_type": credential_device_type, |
| 1102 |
"credential_backed_up": credential_backed_up, |
| 1103 |
"identity_user_id": identity_user_id, |
| 1104 |
"user_agent": user_agent, |
| 1105 |
"user_handle": user_handle, |
| 1106 |
"transports": transports, |
| 1107 |
}, |
| 1108 |
headers={ |
| 1109 |
"content-type": "application/json", |
| 1110 |
}, |
| 1111 |
request_options=request_options, |
| 1112 |
omit=OMIT, |
| 1113 |
) |
| 1114 |
try: |
| 1115 |
if 200 <= _response.status_code < 300: |
| 1116 |
_data = typing.cast( |
| 1117 |
CreateUserAuthenticationMethodResponseContent, |
| 1118 |
parse_obj_as( |
| 1119 |
type_=CreateUserAuthenticationMethodResponseContent, |
| 1120 |
object_=_response.json(), |
| 1121 |
), |
| 1122 |
) |
| 1123 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1124 |
if _response.status_code == 400: |
| 1125 |
raise BadRequestError( |
| 1126 |
headers=dict(_response.headers), |
| 1127 |
body=typing.cast( |
| 1128 |
typing.Any, |
| 1129 |
parse_obj_as( |
| 1130 |
type_=typing.Any, |
| 1131 |
object_=_response.json(), |
| 1132 |
), |
| 1133 |
), |
| 1134 |
) |
| 1135 |
if _response.status_code == 401: |
| 1136 |
raise UnauthorizedError( |
| 1137 |
headers=dict(_response.headers), |
| 1138 |
body=typing.cast( |
| 1139 |
typing.Any, |
| 1140 |
parse_obj_as( |
| 1141 |
type_=typing.Any, |
| 1142 |
object_=_response.json(), |
| 1143 |
), |
| 1144 |
), |
| 1145 |
) |
| 1146 |
if _response.status_code == 403: |
| 1147 |
raise ForbiddenError( |
| 1148 |
headers=dict(_response.headers), |
| 1149 |
body=typing.cast( |
| 1150 |
typing.Any, |
| 1151 |
parse_obj_as( |
| 1152 |
type_=typing.Any, |
| 1153 |
object_=_response.json(), |
| 1154 |
), |
| 1155 |
), |
| 1156 |
) |
| 1157 |
if _response.status_code == 404: |
| 1158 |
raise NotFoundError( |
| 1159 |
headers=dict(_response.headers), |
| 1160 |
body=typing.cast( |
| 1161 |
typing.Any, |
| 1162 |
parse_obj_as( |
| 1163 |
type_=typing.Any, |
| 1164 |
object_=_response.json(), |
| 1165 |
), |
| 1166 |
), |
| 1167 |
) |
| 1168 |
if _response.status_code == 409: |
| 1169 |
raise ConflictError( |
| 1170 |
headers=dict(_response.headers), |
| 1171 |
body=typing.cast( |
| 1172 |
typing.Any, |
| 1173 |
parse_obj_as( |
| 1174 |
type_=typing.Any, |
| 1175 |
object_=_response.json(), |
| 1176 |
), |
| 1177 |
), |
| 1178 |
) |
| 1179 |
if _response.status_code == 429: |
| 1180 |
raise TooManyRequestsError( |
| 1181 |
headers=dict(_response.headers), |
| 1182 |
body=typing.cast( |
| 1183 |
typing.Any, |
| 1184 |
parse_obj_as( |
| 1185 |
type_=typing.Any, |
| 1186 |
object_=_response.json(), |
| 1187 |
), |
| 1188 |
), |
| 1189 |
) |
| 1190 |
_response_json = _response.json() |
| 1191 |
except JSONDecodeError: |
| 1192 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1193 |
except ValidationError as e: |
| 1194 |
raise ParsingError( |
| 1195 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1196 |
) |
| 1197 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1198 |
|
| 1199 |
async def set( |
| 1200 |
self, |
| 1201 |
id: str, |
| 1202 |
*, |
| 1203 |
request: SetUserAuthenticationMethodsRequestContent, |
| 1204 |
request_options: typing.Optional[RequestOptions] = None, |
| 1205 |
) -> AsyncHttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]]: |
| 1206 |
""" |
| 1207 |
Replace the specified user <a href="https://auth0.com/docs/secure/multi-factor-authentication/multi-factor-authentication-factors"> authentication methods</a> with supplied values. |
| 1208 |
|
| 1209 |
<b>Note</b>: Authentication methods supplied through this action do not iterate on existing methods. Instead, any methods passed will overwrite the user’s existing settings. |
| 1210 |
|
| 1211 |
Parameters |
| 1212 |
---------- |
| 1213 |
id : str |
| 1214 |
The ID of the user in question. |
| 1215 |
|
| 1216 |
request : SetUserAuthenticationMethodsRequestContent |
| 1217 |
|
| 1218 |
request_options : typing.Optional[RequestOptions] |
| 1219 |
Request-specific configuration. |
| 1220 |
|
| 1221 |
Returns |
| 1222 |
------- |
| 1223 |
AsyncHttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]] |
| 1224 |
All authentication methods successfully updated. |
| 1225 |
""" |
| 1226 |
_response = await self._client_wrapper.httpx_client.request( |
| 1227 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 1228 |
method="PUT", |
| 1229 |
json=convert_and_respect_annotation_metadata( |
| 1230 |
object_=request, annotation=SetUserAuthenticationMethodsRequestContent, direction="write" |
| 1231 |
), |
| 1232 |
request_options=request_options, |
| 1233 |
omit=OMIT, |
| 1234 |
) |
| 1235 |
try: |
| 1236 |
if 200 <= _response.status_code < 300: |
| 1237 |
_data = typing.cast( |
| 1238 |
typing.List[SetUserAuthenticationMethodResponseContent], |
| 1239 |
parse_obj_as( |
| 1240 |
type_=typing.List[SetUserAuthenticationMethodResponseContent], |
| 1241 |
object_=_response.json(), |
| 1242 |
), |
| 1243 |
) |
| 1244 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1245 |
if _response.status_code == 400: |
| 1246 |
raise BadRequestError( |
| 1247 |
headers=dict(_response.headers), |
| 1248 |
body=typing.cast( |
| 1249 |
typing.Any, |
| 1250 |
parse_obj_as( |
| 1251 |
type_=typing.Any, |
| 1252 |
object_=_response.json(), |
| 1253 |
), |
| 1254 |
), |
| 1255 |
) |
| 1256 |
if _response.status_code == 401: |
| 1257 |
raise UnauthorizedError( |
| 1258 |
headers=dict(_response.headers), |
| 1259 |
body=typing.cast( |
| 1260 |
typing.Any, |
| 1261 |
parse_obj_as( |
| 1262 |
type_=typing.Any, |
| 1263 |
object_=_response.json(), |
| 1264 |
), |
| 1265 |
), |
| 1266 |
) |
| 1267 |
if _response.status_code == 403: |
| 1268 |
raise ForbiddenError( |
| 1269 |
headers=dict(_response.headers), |
| 1270 |
body=typing.cast( |
| 1271 |
typing.Any, |
| 1272 |
parse_obj_as( |
| 1273 |
type_=typing.Any, |
| 1274 |
object_=_response.json(), |
| 1275 |
), |
| 1276 |
), |
| 1277 |
) |
| 1278 |
if _response.status_code == 409: |
| 1279 |
raise ConflictError( |
| 1280 |
headers=dict(_response.headers), |
| 1281 |
body=typing.cast( |
| 1282 |
typing.Any, |
| 1283 |
parse_obj_as( |
| 1284 |
type_=typing.Any, |
| 1285 |
object_=_response.json(), |
| 1286 |
), |
| 1287 |
), |
| 1288 |
) |
| 1289 |
if _response.status_code == 429: |
| 1290 |
raise TooManyRequestsError( |
| 1291 |
headers=dict(_response.headers), |
| 1292 |
body=typing.cast( |
| 1293 |
typing.Any, |
| 1294 |
parse_obj_as( |
| 1295 |
type_=typing.Any, |
| 1296 |
object_=_response.json(), |
| 1297 |
), |
| 1298 |
), |
| 1299 |
) |
| 1300 |
_response_json = _response.json() |
| 1301 |
except JSONDecodeError: |
| 1302 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1303 |
except ValidationError as e: |
| 1304 |
raise ParsingError( |
| 1305 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1306 |
) |
| 1307 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1308 |
|
| 1309 |
async def delete_all( |
| 1310 |
self, id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 1311 |
) -> AsyncHttpResponse[None]: |
| 1312 |
""" |
| 1313 |
Remove all authentication methods (i.e., enrolled MFA factors) from the specified user account. This action cannot be undone. |
| 1314 |
|
| 1315 |
Parameters |
| 1316 |
---------- |
| 1317 |
id : str |
| 1318 |
The ID of the user in question. |
| 1319 |
|
| 1320 |
request_options : typing.Optional[RequestOptions] |
| 1321 |
Request-specific configuration. |
| 1322 |
|
| 1323 |
Returns |
| 1324 |
------- |
| 1325 |
AsyncHttpResponse[None] |
| 1326 |
""" |
| 1327 |
_response = await self._client_wrapper.httpx_client.request( |
| 1328 |
f"users/{encode_path_param(id)}/authentication-methods", |
| 1329 |
method="DELETE", |
| 1330 |
request_options=request_options, |
| 1331 |
) |
| 1332 |
try: |
| 1333 |
if 200 <= _response.status_code < 300: |
| 1334 |
return AsyncHttpResponse(response=_response, data=None) |
| 1335 |
if _response.status_code == 400: |
| 1336 |
raise BadRequestError( |
| 1337 |
headers=dict(_response.headers), |
| 1338 |
body=typing.cast( |
| 1339 |
typing.Any, |
| 1340 |
parse_obj_as( |
| 1341 |
type_=typing.Any, |
| 1342 |
object_=_response.json(), |
| 1343 |
), |
| 1344 |
), |
| 1345 |
) |
| 1346 |
if _response.status_code == 401: |
| 1347 |
raise UnauthorizedError( |
| 1348 |
headers=dict(_response.headers), |
| 1349 |
body=typing.cast( |
| 1350 |
typing.Any, |
| 1351 |
parse_obj_as( |
| 1352 |
type_=typing.Any, |
| 1353 |
object_=_response.json(), |
| 1354 |
), |
| 1355 |
), |
| 1356 |
) |
| 1357 |
if _response.status_code == 403: |
| 1358 |
raise ForbiddenError( |
| 1359 |
headers=dict(_response.headers), |
| 1360 |
body=typing.cast( |
| 1361 |
typing.Any, |
| 1362 |
parse_obj_as( |
| 1363 |
type_=typing.Any, |
| 1364 |
object_=_response.json(), |
| 1365 |
), |
| 1366 |
), |
| 1367 |
) |
| 1368 |
if _response.status_code == 429: |
| 1369 |
raise TooManyRequestsError( |
| 1370 |
headers=dict(_response.headers), |
| 1371 |
body=typing.cast( |
| 1372 |
typing.Any, |
| 1373 |
parse_obj_as( |
| 1374 |
type_=typing.Any, |
| 1375 |
object_=_response.json(), |
| 1376 |
), |
| 1377 |
), |
| 1378 |
) |
| 1379 |
_response_json = _response.json() |
| 1380 |
except JSONDecodeError: |
| 1381 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1382 |
except ValidationError as e: |
| 1383 |
raise ParsingError( |
| 1384 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1385 |
) |
| 1386 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1387 |
|
| 1388 |
async def get( |
| 1389 |
self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 1390 |
) -> AsyncHttpResponse[GetUserAuthenticationMethodResponseContent]: |
| 1391 |
""" |
| 1392 |
Parameters |
| 1393 |
---------- |
| 1394 |
id : str |
| 1395 |
The ID of the user in question. |
| 1396 |
|
| 1397 |
authentication_method_id : str |
| 1398 |
The ID of the authentication methods in question. |
| 1399 |
|
| 1400 |
request_options : typing.Optional[RequestOptions] |
| 1401 |
Request-specific configuration. |
| 1402 |
|
| 1403 |
Returns |
| 1404 |
------- |
| 1405 |
AsyncHttpResponse[GetUserAuthenticationMethodResponseContent] |
| 1406 |
Authentication method retrieved. |
| 1407 |
""" |
| 1408 |
_response = await self._client_wrapper.httpx_client.request( |
| 1409 |
f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", |
| 1410 |
method="GET", |
| 1411 |
request_options=request_options, |
| 1412 |
) |
| 1413 |
try: |
| 1414 |
if 200 <= _response.status_code < 300: |
| 1415 |
_data = typing.cast( |
| 1416 |
GetUserAuthenticationMethodResponseContent, |
| 1417 |
parse_obj_as( |
| 1418 |
type_=GetUserAuthenticationMethodResponseContent, |
| 1419 |
object_=_response.json(), |
| 1420 |
), |
| 1421 |
) |
| 1422 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1423 |
if _response.status_code == 400: |
| 1424 |
raise BadRequestError( |
| 1425 |
headers=dict(_response.headers), |
| 1426 |
body=typing.cast( |
| 1427 |
typing.Any, |
| 1428 |
parse_obj_as( |
| 1429 |
type_=typing.Any, |
| 1430 |
object_=_response.json(), |
| 1431 |
), |
| 1432 |
), |
| 1433 |
) |
| 1434 |
if _response.status_code == 401: |
| 1435 |
raise UnauthorizedError( |
| 1436 |
headers=dict(_response.headers), |
| 1437 |
body=typing.cast( |
| 1438 |
typing.Any, |
| 1439 |
parse_obj_as( |
| 1440 |
type_=typing.Any, |
| 1441 |
object_=_response.json(), |
| 1442 |
), |
| 1443 |
), |
| 1444 |
) |
| 1445 |
if _response.status_code == 403: |
| 1446 |
raise ForbiddenError( |
| 1447 |
headers=dict(_response.headers), |
| 1448 |
body=typing.cast( |
| 1449 |
typing.Any, |
| 1450 |
parse_obj_as( |
| 1451 |
type_=typing.Any, |
| 1452 |
object_=_response.json(), |
| 1453 |
), |
| 1454 |
), |
| 1455 |
) |
| 1456 |
if _response.status_code == 404: |
| 1457 |
raise NotFoundError( |
| 1458 |
headers=dict(_response.headers), |
| 1459 |
body=typing.cast( |
| 1460 |
typing.Any, |
| 1461 |
parse_obj_as( |
| 1462 |
type_=typing.Any, |
| 1463 |
object_=_response.json(), |
| 1464 |
), |
| 1465 |
), |
| 1466 |
) |
| 1467 |
if _response.status_code == 429: |
| 1468 |
raise TooManyRequestsError( |
| 1469 |
headers=dict(_response.headers), |
| 1470 |
body=typing.cast( |
| 1471 |
typing.Any, |
| 1472 |
parse_obj_as( |
| 1473 |
type_=typing.Any, |
| 1474 |
object_=_response.json(), |
| 1475 |
), |
| 1476 |
), |
| 1477 |
) |
| 1478 |
_response_json = _response.json() |
| 1479 |
except JSONDecodeError: |
| 1480 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1481 |
except ValidationError as e: |
| 1482 |
raise ParsingError( |
| 1483 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1484 |
) |
| 1485 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1486 |
|
| 1487 |
async def delete( |
| 1488 |
self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 1489 |
) -> AsyncHttpResponse[None]: |
| 1490 |
""" |
| 1491 |
Remove the authentication method with the given ID from the specified user. For more information, review <a href="https://auth0.com/docs/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authentication-methods-with-management-api">Manage Authentication Methods with Management API</a>. |
| 1492 |
|
| 1493 |
Parameters |
| 1494 |
---------- |
| 1495 |
id : str |
| 1496 |
The ID of the user in question. |
| 1497 |
|
| 1498 |
authentication_method_id : str |
| 1499 |
The ID of the authentication method to delete. |
| 1500 |
|
| 1501 |
request_options : typing.Optional[RequestOptions] |
| 1502 |
Request-specific configuration. |
| 1503 |
|
| 1504 |
Returns |
| 1505 |
------- |
| 1506 |
AsyncHttpResponse[None] |
| 1507 |
""" |
| 1508 |
_response = await self._client_wrapper.httpx_client.request( |
| 1509 |
f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", |
| 1510 |
method="DELETE", |
| 1511 |
request_options=request_options, |
| 1512 |
) |
| 1513 |
try: |
| 1514 |
if 200 <= _response.status_code < 300: |
| 1515 |
return AsyncHttpResponse(response=_response, data=None) |
| 1516 |
if _response.status_code == 400: |
| 1517 |
raise BadRequestError( |
| 1518 |
headers=dict(_response.headers), |
| 1519 |
body=typing.cast( |
| 1520 |
typing.Any, |
| 1521 |
parse_obj_as( |
| 1522 |
type_=typing.Any, |
| 1523 |
object_=_response.json(), |
| 1524 |
), |
| 1525 |
), |
| 1526 |
) |
| 1527 |
if _response.status_code == 401: |
| 1528 |
raise UnauthorizedError( |
| 1529 |
headers=dict(_response.headers), |
| 1530 |
body=typing.cast( |
| 1531 |
typing.Any, |
| 1532 |
parse_obj_as( |
| 1533 |
type_=typing.Any, |
| 1534 |
object_=_response.json(), |
| 1535 |
), |
| 1536 |
), |
| 1537 |
) |
| 1538 |
if _response.status_code == 403: |
| 1539 |
raise ForbiddenError( |
| 1540 |
headers=dict(_response.headers), |
| 1541 |
body=typing.cast( |
| 1542 |
typing.Any, |
| 1543 |
parse_obj_as( |
| 1544 |
type_=typing.Any, |
| 1545 |
object_=_response.json(), |
| 1546 |
), |
| 1547 |
), |
| 1548 |
) |
| 1549 |
if _response.status_code == 404: |
| 1550 |
raise NotFoundError( |
| 1551 |
headers=dict(_response.headers), |
| 1552 |
body=typing.cast( |
| 1553 |
typing.Any, |
| 1554 |
parse_obj_as( |
| 1555 |
type_=typing.Any, |
| 1556 |
object_=_response.json(), |
| 1557 |
), |
| 1558 |
), |
| 1559 |
) |
| 1560 |
if _response.status_code == 429: |
| 1561 |
raise TooManyRequestsError( |
| 1562 |
headers=dict(_response.headers), |
| 1563 |
body=typing.cast( |
| 1564 |
typing.Any, |
| 1565 |
parse_obj_as( |
| 1566 |
type_=typing.Any, |
| 1567 |
object_=_response.json(), |
| 1568 |
), |
| 1569 |
), |
| 1570 |
) |
| 1571 |
_response_json = _response.json() |
| 1572 |
except JSONDecodeError: |
| 1573 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1574 |
except ValidationError as e: |
| 1575 |
raise ParsingError( |
| 1576 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1577 |
) |
| 1578 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1579 |
|
| 1580 |
async def update( |
| 1581 |
self, |
| 1582 |
id: str, |
| 1583 |
authentication_method_id: str, |
| 1584 |
*, |
| 1585 |
name: typing.Optional[str] = OMIT, |
| 1586 |
preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, |
| 1587 |
request_options: typing.Optional[RequestOptions] = None, |
| 1588 |
) -> AsyncHttpResponse[UpdateUserAuthenticationMethodResponseContent]: |
| 1589 |
""" |
| 1590 |
Modify the authentication method with the given ID from the specified user. For more information, review <a href="https://auth0.com/docs/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authentication-methods-with-management-api">Manage Authentication Methods with Management API</a>. |
| 1591 |
|
| 1592 |
Parameters |
| 1593 |
---------- |
| 1594 |
id : str |
| 1595 |
The ID of the user in question. |
| 1596 |
|
| 1597 |
authentication_method_id : str |
| 1598 |
The ID of the authentication method to update. |
| 1599 |
|
| 1600 |
name : typing.Optional[str] |
| 1601 |
A human-readable label to identify the authentication method. |
| 1602 |
|
| 1603 |
preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] |
| 1604 |
Preferred phone authentication method |
| 1605 |
|
| 1606 |
request_options : typing.Optional[RequestOptions] |
| 1607 |
Request-specific configuration. |
| 1608 |
|
| 1609 |
Returns |
| 1610 |
------- |
| 1611 |
AsyncHttpResponse[UpdateUserAuthenticationMethodResponseContent] |
| 1612 |
Authentication method updated. |
| 1613 |
""" |
| 1614 |
_response = await self._client_wrapper.httpx_client.request( |
| 1615 |
f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", |
| 1616 |
method="PATCH", |
| 1617 |
json={ |
| 1618 |
"name": name, |
| 1619 |
"preferred_authentication_method": preferred_authentication_method, |
| 1620 |
}, |
| 1621 |
headers={ |
| 1622 |
"content-type": "application/json", |
| 1623 |
}, |
| 1624 |
request_options=request_options, |
| 1625 |
omit=OMIT, |
| 1626 |
) |
| 1627 |
try: |
| 1628 |
if 200 <= _response.status_code < 300: |
| 1629 |
_data = typing.cast( |
| 1630 |
UpdateUserAuthenticationMethodResponseContent, |
| 1631 |
parse_obj_as( |
| 1632 |
type_=UpdateUserAuthenticationMethodResponseContent, |
| 1633 |
object_=_response.json(), |
| 1634 |
), |
| 1635 |
) |
| 1636 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1637 |
if _response.status_code == 400: |
| 1638 |
raise BadRequestError( |
| 1639 |
headers=dict(_response.headers), |
| 1640 |
body=typing.cast( |
| 1641 |
typing.Any, |
| 1642 |
parse_obj_as( |
| 1643 |
type_=typing.Any, |
| 1644 |
object_=_response.json(), |
| 1645 |
), |
| 1646 |
), |
| 1647 |
) |
| 1648 |
if _response.status_code == 401: |
| 1649 |
raise UnauthorizedError( |
| 1650 |
headers=dict(_response.headers), |
| 1651 |
body=typing.cast( |
| 1652 |
typing.Any, |
| 1653 |
parse_obj_as( |
| 1654 |
type_=typing.Any, |
| 1655 |
object_=_response.json(), |
| 1656 |
), |
| 1657 |
), |
| 1658 |
) |
| 1659 |
if _response.status_code == 403: |
| 1660 |
raise ForbiddenError( |
| 1661 |
headers=dict(_response.headers), |
| 1662 |
body=typing.cast( |
| 1663 |
typing.Any, |
| 1664 |
parse_obj_as( |
| 1665 |
type_=typing.Any, |
| 1666 |
object_=_response.json(), |
| 1667 |
), |
| 1668 |
), |
| 1669 |
) |
| 1670 |
if _response.status_code == 404: |
| 1671 |
raise NotFoundError( |
| 1672 |
headers=dict(_response.headers), |
| 1673 |
body=typing.cast( |
| 1674 |
typing.Any, |
| 1675 |
parse_obj_as( |
| 1676 |
type_=typing.Any, |
| 1677 |
object_=_response.json(), |
| 1678 |
), |
| 1679 |
), |
| 1680 |
) |
| 1681 |
if _response.status_code == 429: |
| 1682 |
raise TooManyRequestsError( |
| 1683 |
headers=dict(_response.headers), |
| 1684 |
body=typing.cast( |
| 1685 |
typing.Any, |
| 1686 |
parse_obj_as( |
| 1687 |
type_=typing.Any, |
| 1688 |
object_=_response.json(), |
| 1689 |
), |
| 1690 |
), |
| 1691 |
) |
| 1692 |
_response_json = _response.json() |
| 1693 |
except JSONDecodeError: |
| 1694 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1695 |
except ValidationError as e: |
| 1696 |
raise ParsingError( |
| 1697 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1698 |
) |
| 1699 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |