# This file was auto-generated by Fern from our API Definition. import typing from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.http_response import AsyncHttpResponse, HttpResponse from ...core.jsonable_encoder import encode_path_param from ...core.pagination import AsyncPager, SyncPager from ...core.parse_error import ParsingError from ...core.pydantic_utilities import parse_obj_as from ...core.request_options import RequestOptions from ...core.serialization import convert_and_respect_annotation_metadata from ...errors.bad_request_error import BadRequestError from ...errors.conflict_error import ConflictError from ...errors.forbidden_error import ForbiddenError from ...errors.not_found_error import NotFoundError from ...errors.too_many_requests_error import TooManyRequestsError from ...errors.unauthorized_error import UnauthorizedError from ...types.create_user_authentication_method_response_content import CreateUserAuthenticationMethodResponseContent from ...types.created_user_authentication_method_type_enum import CreatedUserAuthenticationMethodTypeEnum from ...types.credential_device_type_enum import CredentialDeviceTypeEnum from ...types.get_user_authentication_method_response_content import GetUserAuthenticationMethodResponseContent from ...types.list_user_authentication_methods_offset_paginated_response_content import ( ListUserAuthenticationMethodsOffsetPaginatedResponseContent, ) from ...types.preferred_authentication_method_enum import PreferredAuthenticationMethodEnum from ...types.set_user_authentication_method_response_content import SetUserAuthenticationMethodResponseContent from ...types.set_user_authentication_methods_request_content import SetUserAuthenticationMethodsRequestContent from ...types.update_user_authentication_method_response_content import UpdateUserAuthenticationMethodResponseContent from ...types.user_authentication_method import UserAuthenticationMethod from pydantic import ValidationError # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) class RawAuthenticationMethodsClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._client_wrapper = client_wrapper def list( self, id: str, *, page: typing.Optional[int] = 0, per_page: typing.Optional[int] = 50, include_totals: typing.Optional[bool] = True, request_options: typing.Optional[RequestOptions] = None, ) -> SyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent]: """ Retrieve detailed list of authentication methods associated with a specified user. Parameters ---------- id : str The ID of the user in question. page : typing.Optional[int] Page index of the results to return. First page is 0. Default is 0. per_page : typing.Optional[int] Number of results per page. Default is 50. include_totals : typing.Optional[bool] Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- SyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent] The authentication methods for the user were retrieved. """ page = page if page is not None else 0 _response = self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="GET", params={ "page": page, "per_page": per_page, "include_totals": include_totals, }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: _parsed_response = typing.cast( ListUserAuthenticationMethodsOffsetPaginatedResponseContent, parse_obj_as( type_=ListUserAuthenticationMethodsOffsetPaginatedResponseContent, # type: ignore object_=_response.json(), ), ) _items = _parsed_response.authenticators _has_next = len(_items or []) > 0 _get_next = lambda: self.list( id, page=page + 1, per_page=per_page, include_totals=include_totals, request_options=request_options, ) return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) def create( self, id: str, *, type: CreatedUserAuthenticationMethodTypeEnum, name: typing.Optional[str] = OMIT, totp_secret: typing.Optional[str] = OMIT, phone_number: typing.Optional[str] = OMIT, email: typing.Optional[str] = OMIT, preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, key_id: typing.Optional[str] = OMIT, public_key: typing.Optional[str] = OMIT, aaguid: typing.Optional[str] = OMIT, relying_party_identifier: typing.Optional[str] = OMIT, credential_device_type: typing.Optional[CredentialDeviceTypeEnum] = OMIT, credential_backed_up: typing.Optional[bool] = OMIT, identity_user_id: typing.Optional[str] = OMIT, user_agent: typing.Optional[str] = OMIT, user_handle: typing.Optional[str] = OMIT, transports: typing.Optional[typing.Sequence[str]] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> HttpResponse[CreateUserAuthenticationMethodResponseContent]: """ Create an authentication method. Authentication methods created via this endpoint will be auto confirmed and should already have verification completed. Parameters ---------- id : str The ID of the user to whom the new authentication method will be assigned. type : CreatedUserAuthenticationMethodTypeEnum name : typing.Optional[str] A human-readable label to identify the authentication method. totp_secret : typing.Optional[str] Base32 encoded secret for TOTP generation. phone_number : typing.Optional[str] Applies to phone authentication methods only. The destination phone number used to send verification codes via text and voice. email : typing.Optional[str] Applies to email authentication methods only. The email address used to send verification messages. preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] key_id : typing.Optional[str] Applies to webauthn/passkey authentication methods only. The id of the credential. public_key : typing.Optional[str] Applies to webauthn/passkey authentication methods only. The public key, which is encoded as base64. aaguid : typing.Optional[str] Applies to passkeys only. Authenticator Attestation Globally Unique Identifier relying_party_identifier : typing.Optional[str] Applies to webauthn authentication methods only. The relying party identifier. credential_device_type : typing.Optional[CredentialDeviceTypeEnum] credential_backed_up : typing.Optional[bool] Applies to passkeys only. Whether the credential was backed up. identity_user_id : typing.Optional[str] Applies to passkeys only. The ID of the user identity linked with the authentication method. user_agent : typing.Optional[str] Applies to passkeys only. The user-agent of the browser used to create the passkey. user_handle : typing.Optional[str] Applies to passkeys only. The user handle of the user identity. transports : typing.Optional[typing.Sequence[str]] Applies to passkeys only. The transports used by clients to communicate with the authenticator. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- HttpResponse[CreateUserAuthenticationMethodResponseContent] Authentication method created. """ _response = self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="POST", json={ "type": type, "name": name, "totp_secret": totp_secret, "phone_number": phone_number, "email": email, "preferred_authentication_method": preferred_authentication_method, "key_id": key_id, "public_key": public_key, "aaguid": aaguid, "relying_party_identifier": relying_party_identifier, "credential_device_type": credential_device_type, "credential_backed_up": credential_backed_up, "identity_user_id": identity_user_id, "user_agent": user_agent, "user_handle": user_handle, "transports": transports, }, headers={ "content-type": "application/json", }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( CreateUserAuthenticationMethodResponseContent, parse_obj_as( type_=CreateUserAuthenticationMethodResponseContent, # type: ignore object_=_response.json(), ), ) return HttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 409: raise ConflictError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) def set( self, id: str, *, request: SetUserAuthenticationMethodsRequestContent, request_options: typing.Optional[RequestOptions] = None, ) -> HttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]]: """ Replace the specified user authentication methods with supplied values. Note: Authentication methods supplied through this action do not iterate on existing methods. Instead, any methods passed will overwrite the user’s existing settings. Parameters ---------- id : str The ID of the user in question. request : SetUserAuthenticationMethodsRequestContent request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- HttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]] All authentication methods successfully updated. """ _response = self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="PUT", json=convert_and_respect_annotation_metadata( object_=request, annotation=SetUserAuthenticationMethodsRequestContent, direction="write" ), request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( typing.List[SetUserAuthenticationMethodResponseContent], parse_obj_as( type_=typing.List[SetUserAuthenticationMethodResponseContent], # type: ignore object_=_response.json(), ), ) return HttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 409: raise ConflictError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) def delete_all(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]: """ Remove all authentication methods (i.e., enrolled MFA factors) from the specified user account. This action cannot be undone. Parameters ---------- id : str The ID of the user in question. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- HttpResponse[None] """ _response = self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="DELETE", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return HttpResponse(response=_response, data=None) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) def get( self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> HttpResponse[GetUserAuthenticationMethodResponseContent]: """ Parameters ---------- id : str The ID of the user in question. authentication_method_id : str The ID of the authentication methods in question. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- HttpResponse[GetUserAuthenticationMethodResponseContent] Authentication method retrieved. """ _response = self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", method="GET", request_options=request_options, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( GetUserAuthenticationMethodResponseContent, parse_obj_as( type_=GetUserAuthenticationMethodResponseContent, # type: ignore object_=_response.json(), ), ) return HttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) def delete( self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> HttpResponse[None]: """ Remove the authentication method with the given ID from the specified user. For more information, review Manage Authentication Methods with Management API. Parameters ---------- id : str The ID of the user in question. authentication_method_id : str The ID of the authentication method to delete. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- HttpResponse[None] """ _response = self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", method="DELETE", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return HttpResponse(response=_response, data=None) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) def update( self, id: str, authentication_method_id: str, *, name: typing.Optional[str] = OMIT, preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> HttpResponse[UpdateUserAuthenticationMethodResponseContent]: """ Modify the authentication method with the given ID from the specified user. For more information, review Manage Authentication Methods with Management API. Parameters ---------- id : str The ID of the user in question. authentication_method_id : str The ID of the authentication method to update. name : typing.Optional[str] A human-readable label to identify the authentication method. preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] Preferred phone authentication method request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- HttpResponse[UpdateUserAuthenticationMethodResponseContent] Authentication method updated. """ _response = self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", method="PATCH", json={ "name": name, "preferred_authentication_method": preferred_authentication_method, }, headers={ "content-type": "application/json", }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( UpdateUserAuthenticationMethodResponseContent, parse_obj_as( type_=UpdateUserAuthenticationMethodResponseContent, # type: ignore object_=_response.json(), ), ) return HttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) class AsyncRawAuthenticationMethodsClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._client_wrapper = client_wrapper async def list( self, id: str, *, page: typing.Optional[int] = 0, per_page: typing.Optional[int] = 50, include_totals: typing.Optional[bool] = True, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent]: """ Retrieve detailed list of authentication methods associated with a specified user. Parameters ---------- id : str The ID of the user in question. page : typing.Optional[int] Page index of the results to return. First page is 0. Default is 0. per_page : typing.Optional[int] Number of results per page. Default is 50. include_totals : typing.Optional[bool] Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- AsyncPager[UserAuthenticationMethod, ListUserAuthenticationMethodsOffsetPaginatedResponseContent] The authentication methods for the user were retrieved. """ page = page if page is not None else 0 _response = await self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="GET", params={ "page": page, "per_page": per_page, "include_totals": include_totals, }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: _parsed_response = typing.cast( ListUserAuthenticationMethodsOffsetPaginatedResponseContent, parse_obj_as( type_=ListUserAuthenticationMethodsOffsetPaginatedResponseContent, # type: ignore object_=_response.json(), ), ) _items = _parsed_response.authenticators _has_next = len(_items or []) > 0 async def _get_next(): return await self.list( id, page=page + 1, per_page=per_page, include_totals=include_totals, request_options=request_options, ) return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) async def create( self, id: str, *, type: CreatedUserAuthenticationMethodTypeEnum, name: typing.Optional[str] = OMIT, totp_secret: typing.Optional[str] = OMIT, phone_number: typing.Optional[str] = OMIT, email: typing.Optional[str] = OMIT, preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, key_id: typing.Optional[str] = OMIT, public_key: typing.Optional[str] = OMIT, aaguid: typing.Optional[str] = OMIT, relying_party_identifier: typing.Optional[str] = OMIT, credential_device_type: typing.Optional[CredentialDeviceTypeEnum] = OMIT, credential_backed_up: typing.Optional[bool] = OMIT, identity_user_id: typing.Optional[str] = OMIT, user_agent: typing.Optional[str] = OMIT, user_handle: typing.Optional[str] = OMIT, transports: typing.Optional[typing.Sequence[str]] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncHttpResponse[CreateUserAuthenticationMethodResponseContent]: """ Create an authentication method. Authentication methods created via this endpoint will be auto confirmed and should already have verification completed. Parameters ---------- id : str The ID of the user to whom the new authentication method will be assigned. type : CreatedUserAuthenticationMethodTypeEnum name : typing.Optional[str] A human-readable label to identify the authentication method. totp_secret : typing.Optional[str] Base32 encoded secret for TOTP generation. phone_number : typing.Optional[str] Applies to phone authentication methods only. The destination phone number used to send verification codes via text and voice. email : typing.Optional[str] Applies to email authentication methods only. The email address used to send verification messages. preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] key_id : typing.Optional[str] Applies to webauthn/passkey authentication methods only. The id of the credential. public_key : typing.Optional[str] Applies to webauthn/passkey authentication methods only. The public key, which is encoded as base64. aaguid : typing.Optional[str] Applies to passkeys only. Authenticator Attestation Globally Unique Identifier relying_party_identifier : typing.Optional[str] Applies to webauthn authentication methods only. The relying party identifier. credential_device_type : typing.Optional[CredentialDeviceTypeEnum] credential_backed_up : typing.Optional[bool] Applies to passkeys only. Whether the credential was backed up. identity_user_id : typing.Optional[str] Applies to passkeys only. The ID of the user identity linked with the authentication method. user_agent : typing.Optional[str] Applies to passkeys only. The user-agent of the browser used to create the passkey. user_handle : typing.Optional[str] Applies to passkeys only. The user handle of the user identity. transports : typing.Optional[typing.Sequence[str]] Applies to passkeys only. The transports used by clients to communicate with the authenticator. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- AsyncHttpResponse[CreateUserAuthenticationMethodResponseContent] Authentication method created. """ _response = await self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="POST", json={ "type": type, "name": name, "totp_secret": totp_secret, "phone_number": phone_number, "email": email, "preferred_authentication_method": preferred_authentication_method, "key_id": key_id, "public_key": public_key, "aaguid": aaguid, "relying_party_identifier": relying_party_identifier, "credential_device_type": credential_device_type, "credential_backed_up": credential_backed_up, "identity_user_id": identity_user_id, "user_agent": user_agent, "user_handle": user_handle, "transports": transports, }, headers={ "content-type": "application/json", }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( CreateUserAuthenticationMethodResponseContent, parse_obj_as( type_=CreateUserAuthenticationMethodResponseContent, # type: ignore object_=_response.json(), ), ) return AsyncHttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 409: raise ConflictError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) async def set( self, id: str, *, request: SetUserAuthenticationMethodsRequestContent, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncHttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]]: """ Replace the specified user authentication methods with supplied values. Note: Authentication methods supplied through this action do not iterate on existing methods. Instead, any methods passed will overwrite the user’s existing settings. Parameters ---------- id : str The ID of the user in question. request : SetUserAuthenticationMethodsRequestContent request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- AsyncHttpResponse[typing.List[SetUserAuthenticationMethodResponseContent]] All authentication methods successfully updated. """ _response = await self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="PUT", json=convert_and_respect_annotation_metadata( object_=request, annotation=SetUserAuthenticationMethodsRequestContent, direction="write" ), request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( typing.List[SetUserAuthenticationMethodResponseContent], parse_obj_as( type_=typing.List[SetUserAuthenticationMethodResponseContent], # type: ignore object_=_response.json(), ), ) return AsyncHttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 409: raise ConflictError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) async def delete_all( self, id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> AsyncHttpResponse[None]: """ Remove all authentication methods (i.e., enrolled MFA factors) from the specified user account. This action cannot be undone. Parameters ---------- id : str The ID of the user in question. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- AsyncHttpResponse[None] """ _response = await self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods", method="DELETE", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return AsyncHttpResponse(response=_response, data=None) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) async def get( self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> AsyncHttpResponse[GetUserAuthenticationMethodResponseContent]: """ Parameters ---------- id : str The ID of the user in question. authentication_method_id : str The ID of the authentication methods in question. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- AsyncHttpResponse[GetUserAuthenticationMethodResponseContent] Authentication method retrieved. """ _response = await self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", method="GET", request_options=request_options, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( GetUserAuthenticationMethodResponseContent, parse_obj_as( type_=GetUserAuthenticationMethodResponseContent, # type: ignore object_=_response.json(), ), ) return AsyncHttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) async def delete( self, id: str, authentication_method_id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> AsyncHttpResponse[None]: """ Remove the authentication method with the given ID from the specified user. For more information, review Manage Authentication Methods with Management API. Parameters ---------- id : str The ID of the user in question. authentication_method_id : str The ID of the authentication method to delete. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- AsyncHttpResponse[None] """ _response = await self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", method="DELETE", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return AsyncHttpResponse(response=_response, data=None) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) async def update( self, id: str, authentication_method_id: str, *, name: typing.Optional[str] = OMIT, preferred_authentication_method: typing.Optional[PreferredAuthenticationMethodEnum] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncHttpResponse[UpdateUserAuthenticationMethodResponseContent]: """ Modify the authentication method with the given ID from the specified user. For more information, review Manage Authentication Methods with Management API. Parameters ---------- id : str The ID of the user in question. authentication_method_id : str The ID of the authentication method to update. name : typing.Optional[str] A human-readable label to identify the authentication method. preferred_authentication_method : typing.Optional[PreferredAuthenticationMethodEnum] Preferred phone authentication method request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- AsyncHttpResponse[UpdateUserAuthenticationMethodResponseContent] Authentication method updated. """ _response = await self._client_wrapper.httpx_client.request( f"users/{encode_path_param(id)}/authentication-methods/{encode_path_param(authentication_method_id)}", method="PATCH", json={ "name": name, "preferred_authentication_method": preferred_authentication_method, }, headers={ "content-type": "application/json", }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: _data = typing.cast( UpdateUserAuthenticationMethodResponseContent, parse_obj_as( type_=UpdateUserAuthenticationMethodResponseContent, # type: ignore object_=_response.json(), ), ) return AsyncHttpResponse(response=_response, data=_data) if _response.status_code == 400: raise BadRequestError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 401: raise UnauthorizedError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 403: raise ForbiddenError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 404: raise NotFoundError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( typing.Any, parse_obj_as( type_=typing.Any, # type: ignore object_=_response.json(), ), ), ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) except ValidationError as e: raise ParsingError( status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)