# 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.parse_error import ParsingError
from ...core.pydantic_utilities import parse_obj_as
from ...core.request_options import RequestOptions
from ...errors.bad_request_error import BadRequestError
from ...errors.forbidden_error import ForbiddenError
from ...errors.not_found_error import NotFoundError
from ...errors.unauthorized_error import UnauthorizedError
from ...types.create_guardian_enrollment_ticket_response_content import CreateGuardianEnrollmentTicketResponseContent
from ...types.get_guardian_enrollment_response_content import GetGuardianEnrollmentResponseContent
from ...types.guardian_enrollment_factor_enum import GuardianEnrollmentFactorEnum
from pydantic import ValidationError
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class RawEnrollmentsClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._client_wrapper = client_wrapper
def create_ticket(
self,
*,
user_id: str,
email: typing.Optional[str] = OMIT,
send_mail: typing.Optional[bool] = OMIT,
email_locale: typing.Optional[str] = OMIT,
factor: typing.Optional[GuardianEnrollmentFactorEnum] = OMIT,
allow_multiple_enrollments: typing.Optional[bool] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CreateGuardianEnrollmentTicketResponseContent]:
"""
Create a [multi-factor authentication (MFA) enrollment ticket](https://auth0.com/docs/secure/multi-factor-authentication/auth0-guardian/create-custom-enrollment-tickets), and optionally send an email with the created ticket to a given user. Enrollment tickets can specify which factor users must enroll with or allow existing MFA users to enroll in additional factors.
Parameters
----------
user_id : str
user_id for the enrollment ticket
email : typing.Optional[str]
alternate email to which the enrollment email will be sent. Optional - by default, the email will be sent to the user's default address
send_mail : typing.Optional[bool]
Send an email to the user to start the enrollment
email_locale : typing.Optional[str]
Optional. Specify the locale of the enrollment email. Used with send_email.
factor : typing.Optional[GuardianEnrollmentFactorEnum]
allow_multiple_enrollments : typing.Optional[bool]
Optional. Allows a user who has previously enrolled in MFA to enroll with additional factors.
Note: Parameter can only be used with Universal Login; it cannot be used with Classic Login or custom MFA pages.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[CreateGuardianEnrollmentTicketResponseContent]
Enrollment ticket successfully created.
"""
_response = self._client_wrapper.httpx_client.request(
"guardian/enrollments/ticket",
method="POST",
json={
"user_id": user_id,
"email": email,
"send_mail": send_mail,
"email_locale": email_locale,
"factor": factor,
"allow_multiple_enrollments": allow_multiple_enrollments,
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
CreateGuardianEnrollmentTicketResponseContent,
parse_obj_as(
type_=CreateGuardianEnrollmentTicketResponseContent, # 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(),
),
),
)
_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, *, request_options: typing.Optional[RequestOptions] = None
) -> HttpResponse[GetGuardianEnrollmentResponseContent]:
"""
Retrieve details, such as status and type, for a specific multi-factor authentication enrollment registered to a user account.
Parameters
----------
id : str
ID of the enrollment to be retrieve.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[GetGuardianEnrollmentResponseContent]
Enrollment successfully retrieved.
"""
_response = self._client_wrapper.httpx_client.request(
f"guardian/enrollments/{encode_path_param(id)}",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetGuardianEnrollmentResponseContent,
parse_obj_as(
type_=GetGuardianEnrollmentResponseContent, # 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(),
),
),
)
_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, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
"""
Remove a specific multi-factor authentication (MFA) enrollment from a user's account. This allows the user to re-enroll with MFA. For more information, review [Reset User Multi-Factor Authentication and Recovery Codes](https://auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa).
Parameters
----------
id : str
ID of the enrollment to be deleted.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[None]
"""
_response = self._client_wrapper.httpx_client.request(
f"guardian/enrollments/{encode_path_param(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(),
),
),
)
_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 AsyncRawEnrollmentsClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._client_wrapper = client_wrapper
async def create_ticket(
self,
*,
user_id: str,
email: typing.Optional[str] = OMIT,
send_mail: typing.Optional[bool] = OMIT,
email_locale: typing.Optional[str] = OMIT,
factor: typing.Optional[GuardianEnrollmentFactorEnum] = OMIT,
allow_multiple_enrollments: typing.Optional[bool] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[CreateGuardianEnrollmentTicketResponseContent]:
"""
Create a [multi-factor authentication (MFA) enrollment ticket](https://auth0.com/docs/secure/multi-factor-authentication/auth0-guardian/create-custom-enrollment-tickets), and optionally send an email with the created ticket to a given user. Enrollment tickets can specify which factor users must enroll with or allow existing MFA users to enroll in additional factors.
Parameters
----------
user_id : str
user_id for the enrollment ticket
email : typing.Optional[str]
alternate email to which the enrollment email will be sent. Optional - by default, the email will be sent to the user's default address
send_mail : typing.Optional[bool]
Send an email to the user to start the enrollment
email_locale : typing.Optional[str]
Optional. Specify the locale of the enrollment email. Used with send_email.
factor : typing.Optional[GuardianEnrollmentFactorEnum]
allow_multiple_enrollments : typing.Optional[bool]
Optional. Allows a user who has previously enrolled in MFA to enroll with additional factors.
Note: Parameter can only be used with Universal Login; it cannot be used with Classic Login or custom MFA pages.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[CreateGuardianEnrollmentTicketResponseContent]
Enrollment ticket successfully created.
"""
_response = await self._client_wrapper.httpx_client.request(
"guardian/enrollments/ticket",
method="POST",
json={
"user_id": user_id,
"email": email,
"send_mail": send_mail,
"email_locale": email_locale,
"factor": factor,
"allow_multiple_enrollments": allow_multiple_enrollments,
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
CreateGuardianEnrollmentTicketResponseContent,
parse_obj_as(
type_=CreateGuardianEnrollmentTicketResponseContent, # 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(),
),
),
)
_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, *, request_options: typing.Optional[RequestOptions] = None
) -> AsyncHttpResponse[GetGuardianEnrollmentResponseContent]:
"""
Retrieve details, such as status and type, for a specific multi-factor authentication enrollment registered to a user account.
Parameters
----------
id : str
ID of the enrollment to be retrieve.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[GetGuardianEnrollmentResponseContent]
Enrollment successfully retrieved.
"""
_response = await self._client_wrapper.httpx_client.request(
f"guardian/enrollments/{encode_path_param(id)}",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetGuardianEnrollmentResponseContent,
parse_obj_as(
type_=GetGuardianEnrollmentResponseContent, # 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(),
),
),
)
_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, *, request_options: typing.Optional[RequestOptions] = None
) -> AsyncHttpResponse[None]:
"""
Remove a specific multi-factor authentication (MFA) enrollment from a user's account. This allows the user to re-enroll with MFA. For more information, review [Reset User Multi-Factor Authentication and Recovery Codes](https://auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa).
Parameters
----------
id : str
ID of the enrollment to be deleted.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[None]
"""
_response = await self._client_wrapper.httpx_client.request(
f"guardian/enrollments/{encode_path_param(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(),
),
),
)
_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)