| 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.parse_error import ParsingError |
| 11 |
from ...core.pydantic_utilities import parse_obj_as |
| 12 |
from ...core.request_options import RequestOptions |
| 13 |
from ...errors.bad_request_error import BadRequestError |
| 14 |
from ...errors.forbidden_error import ForbiddenError |
| 15 |
from ...errors.unauthorized_error import UnauthorizedError |
| 16 |
from ...types.guardian_factor import GuardianFactor |
| 17 |
from ...types.guardian_factor_name_enum import GuardianFactorNameEnum |
| 18 |
from ...types.set_guardian_factor_response_content import SetGuardianFactorResponseContent |
| 19 |
from pydantic import ValidationError |
| 20 |
|
| 21 |
|
| 22 |
OMIT = typing.cast(typing.Any, ...) |
| 23 |
|
| 24 |
|
| 25 |
class RawFactorsClient: |
| 26 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 27 |
self._client_wrapper = client_wrapper |
| 28 |
|
| 29 |
def list( |
| 30 |
self, *, request_options: typing.Optional[RequestOptions] = None |
| 31 |
) -> HttpResponse[typing.List[GuardianFactor]]: |
| 32 |
""" |
| 33 |
Retrieve details of all <a href="https://auth0.com/docs/secure/multi-factor-authentication/multi-factor-authentication-factors">multi-factor authentication factors</a> associated with your tenant. |
| 34 |
|
| 35 |
Parameters |
| 36 |
---------- |
| 37 |
request_options : typing.Optional[RequestOptions] |
| 38 |
Request-specific configuration. |
| 39 |
|
| 40 |
Returns |
| 41 |
------- |
| 42 |
HttpResponse[typing.List[GuardianFactor]] |
| 43 |
Factors successfully retrieved. |
| 44 |
""" |
| 45 |
_response = self._client_wrapper.httpx_client.request( |
| 46 |
"guardian/factors", |
| 47 |
method="GET", |
| 48 |
request_options=request_options, |
| 49 |
) |
| 50 |
try: |
| 51 |
if 200 <= _response.status_code < 300: |
| 52 |
_data = typing.cast( |
| 53 |
typing.List[GuardianFactor], |
| 54 |
parse_obj_as( |
| 55 |
type_=typing.List[GuardianFactor], |
| 56 |
object_=_response.json(), |
| 57 |
), |
| 58 |
) |
| 59 |
return HttpResponse(response=_response, data=_data) |
| 60 |
if _response.status_code == 400: |
| 61 |
raise BadRequestError( |
| 62 |
headers=dict(_response.headers), |
| 63 |
body=typing.cast( |
| 64 |
typing.Any, |
| 65 |
parse_obj_as( |
| 66 |
type_=typing.Any, |
| 67 |
object_=_response.json(), |
| 68 |
), |
| 69 |
), |
| 70 |
) |
| 71 |
if _response.status_code == 401: |
| 72 |
raise UnauthorizedError( |
| 73 |
headers=dict(_response.headers), |
| 74 |
body=typing.cast( |
| 75 |
typing.Any, |
| 76 |
parse_obj_as( |
| 77 |
type_=typing.Any, |
| 78 |
object_=_response.json(), |
| 79 |
), |
| 80 |
), |
| 81 |
) |
| 82 |
if _response.status_code == 403: |
| 83 |
raise ForbiddenError( |
| 84 |
headers=dict(_response.headers), |
| 85 |
body=typing.cast( |
| 86 |
typing.Any, |
| 87 |
parse_obj_as( |
| 88 |
type_=typing.Any, |
| 89 |
object_=_response.json(), |
| 90 |
), |
| 91 |
), |
| 92 |
) |
| 93 |
_response_json = _response.json() |
| 94 |
except JSONDecodeError: |
| 95 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 96 |
except ValidationError as e: |
| 97 |
raise ParsingError( |
| 98 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 99 |
) |
| 100 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 101 |
|
| 102 |
def set( |
| 103 |
self, name: GuardianFactorNameEnum, *, enabled: bool, request_options: typing.Optional[RequestOptions] = None |
| 104 |
) -> HttpResponse[SetGuardianFactorResponseContent]: |
| 105 |
""" |
| 106 |
Update the status (i.e., enabled or disabled) of a specific multi-factor authentication factor. |
| 107 |
|
| 108 |
Parameters |
| 109 |
---------- |
| 110 |
name : GuardianFactorNameEnum |
| 111 |
Factor name. Can be `sms`, `push-notification`, `email`, `duo` `otp` `webauthn-roaming`, `webauthn-platform`, or `recovery-code`. |
| 112 |
|
| 113 |
enabled : bool |
| 114 |
Whether this factor is enabled (true) or disabled (false). |
| 115 |
|
| 116 |
request_options : typing.Optional[RequestOptions] |
| 117 |
Request-specific configuration. |
| 118 |
|
| 119 |
Returns |
| 120 |
------- |
| 121 |
HttpResponse[SetGuardianFactorResponseContent] |
| 122 |
Factor updated successfully. |
| 123 |
""" |
| 124 |
_response = self._client_wrapper.httpx_client.request( |
| 125 |
f"guardian/factors/{encode_path_param(name)}", |
| 126 |
method="PUT", |
| 127 |
json={ |
| 128 |
"enabled": enabled, |
| 129 |
}, |
| 130 |
headers={ |
| 131 |
"content-type": "application/json", |
| 132 |
}, |
| 133 |
request_options=request_options, |
| 134 |
omit=OMIT, |
| 135 |
) |
| 136 |
try: |
| 137 |
if 200 <= _response.status_code < 300: |
| 138 |
_data = typing.cast( |
| 139 |
SetGuardianFactorResponseContent, |
| 140 |
parse_obj_as( |
| 141 |
type_=SetGuardianFactorResponseContent, |
| 142 |
object_=_response.json(), |
| 143 |
), |
| 144 |
) |
| 145 |
return HttpResponse(response=_response, data=_data) |
| 146 |
if _response.status_code == 400: |
| 147 |
raise BadRequestError( |
| 148 |
headers=dict(_response.headers), |
| 149 |
body=typing.cast( |
| 150 |
typing.Any, |
| 151 |
parse_obj_as( |
| 152 |
type_=typing.Any, |
| 153 |
object_=_response.json(), |
| 154 |
), |
| 155 |
), |
| 156 |
) |
| 157 |
if _response.status_code == 401: |
| 158 |
raise UnauthorizedError( |
| 159 |
headers=dict(_response.headers), |
| 160 |
body=typing.cast( |
| 161 |
typing.Any, |
| 162 |
parse_obj_as( |
| 163 |
type_=typing.Any, |
| 164 |
object_=_response.json(), |
| 165 |
), |
| 166 |
), |
| 167 |
) |
| 168 |
if _response.status_code == 403: |
| 169 |
raise ForbiddenError( |
| 170 |
headers=dict(_response.headers), |
| 171 |
body=typing.cast( |
| 172 |
typing.Any, |
| 173 |
parse_obj_as( |
| 174 |
type_=typing.Any, |
| 175 |
object_=_response.json(), |
| 176 |
), |
| 177 |
), |
| 178 |
) |
| 179 |
_response_json = _response.json() |
| 180 |
except JSONDecodeError: |
| 181 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 182 |
except ValidationError as e: |
| 183 |
raise ParsingError( |
| 184 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 185 |
) |
| 186 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 187 |
|
| 188 |
|
| 189 |
class AsyncRawFactorsClient: |
| 190 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 191 |
self._client_wrapper = client_wrapper |
| 192 |
|
| 193 |
async def list( |
| 194 |
self, *, request_options: typing.Optional[RequestOptions] = None |
| 195 |
) -> AsyncHttpResponse[typing.List[GuardianFactor]]: |
| 196 |
""" |
| 197 |
Retrieve details of all <a href="https://auth0.com/docs/secure/multi-factor-authentication/multi-factor-authentication-factors">multi-factor authentication factors</a> associated with your tenant. |
| 198 |
|
| 199 |
Parameters |
| 200 |
---------- |
| 201 |
request_options : typing.Optional[RequestOptions] |
| 202 |
Request-specific configuration. |
| 203 |
|
| 204 |
Returns |
| 205 |
------- |
| 206 |
AsyncHttpResponse[typing.List[GuardianFactor]] |
| 207 |
Factors successfully retrieved. |
| 208 |
""" |
| 209 |
_response = await self._client_wrapper.httpx_client.request( |
| 210 |
"guardian/factors", |
| 211 |
method="GET", |
| 212 |
request_options=request_options, |
| 213 |
) |
| 214 |
try: |
| 215 |
if 200 <= _response.status_code < 300: |
| 216 |
_data = typing.cast( |
| 217 |
typing.List[GuardianFactor], |
| 218 |
parse_obj_as( |
| 219 |
type_=typing.List[GuardianFactor], |
| 220 |
object_=_response.json(), |
| 221 |
), |
| 222 |
) |
| 223 |
return AsyncHttpResponse(response=_response, data=_data) |
| 224 |
if _response.status_code == 400: |
| 225 |
raise BadRequestError( |
| 226 |
headers=dict(_response.headers), |
| 227 |
body=typing.cast( |
| 228 |
typing.Any, |
| 229 |
parse_obj_as( |
| 230 |
type_=typing.Any, |
| 231 |
object_=_response.json(), |
| 232 |
), |
| 233 |
), |
| 234 |
) |
| 235 |
if _response.status_code == 401: |
| 236 |
raise UnauthorizedError( |
| 237 |
headers=dict(_response.headers), |
| 238 |
body=typing.cast( |
| 239 |
typing.Any, |
| 240 |
parse_obj_as( |
| 241 |
type_=typing.Any, |
| 242 |
object_=_response.json(), |
| 243 |
), |
| 244 |
), |
| 245 |
) |
| 246 |
if _response.status_code == 403: |
| 247 |
raise ForbiddenError( |
| 248 |
headers=dict(_response.headers), |
| 249 |
body=typing.cast( |
| 250 |
typing.Any, |
| 251 |
parse_obj_as( |
| 252 |
type_=typing.Any, |
| 253 |
object_=_response.json(), |
| 254 |
), |
| 255 |
), |
| 256 |
) |
| 257 |
_response_json = _response.json() |
| 258 |
except JSONDecodeError: |
| 259 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 260 |
except ValidationError as e: |
| 261 |
raise ParsingError( |
| 262 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 263 |
) |
| 264 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 265 |
|
| 266 |
async def set( |
| 267 |
self, name: GuardianFactorNameEnum, *, enabled: bool, request_options: typing.Optional[RequestOptions] = None |
| 268 |
) -> AsyncHttpResponse[SetGuardianFactorResponseContent]: |
| 269 |
""" |
| 270 |
Update the status (i.e., enabled or disabled) of a specific multi-factor authentication factor. |
| 271 |
|
| 272 |
Parameters |
| 273 |
---------- |
| 274 |
name : GuardianFactorNameEnum |
| 275 |
Factor name. Can be `sms`, `push-notification`, `email`, `duo` `otp` `webauthn-roaming`, `webauthn-platform`, or `recovery-code`. |
| 276 |
|
| 277 |
enabled : bool |
| 278 |
Whether this factor is enabled (true) or disabled (false). |
| 279 |
|
| 280 |
request_options : typing.Optional[RequestOptions] |
| 281 |
Request-specific configuration. |
| 282 |
|
| 283 |
Returns |
| 284 |
------- |
| 285 |
AsyncHttpResponse[SetGuardianFactorResponseContent] |
| 286 |
Factor updated successfully. |
| 287 |
""" |
| 288 |
_response = await self._client_wrapper.httpx_client.request( |
| 289 |
f"guardian/factors/{encode_path_param(name)}", |
| 290 |
method="PUT", |
| 291 |
json={ |
| 292 |
"enabled": enabled, |
| 293 |
}, |
| 294 |
headers={ |
| 295 |
"content-type": "application/json", |
| 296 |
}, |
| 297 |
request_options=request_options, |
| 298 |
omit=OMIT, |
| 299 |
) |
| 300 |
try: |
| 301 |
if 200 <= _response.status_code < 300: |
| 302 |
_data = typing.cast( |
| 303 |
SetGuardianFactorResponseContent, |
| 304 |
parse_obj_as( |
| 305 |
type_=SetGuardianFactorResponseContent, |
| 306 |
object_=_response.json(), |
| 307 |
), |
| 308 |
) |
| 309 |
return AsyncHttpResponse(response=_response, data=_data) |
| 310 |
if _response.status_code == 400: |
| 311 |
raise BadRequestError( |
| 312 |
headers=dict(_response.headers), |
| 313 |
body=typing.cast( |
| 314 |
typing.Any, |
| 315 |
parse_obj_as( |
| 316 |
type_=typing.Any, |
| 317 |
object_=_response.json(), |
| 318 |
), |
| 319 |
), |
| 320 |
) |
| 321 |
if _response.status_code == 401: |
| 322 |
raise UnauthorizedError( |
| 323 |
headers=dict(_response.headers), |
| 324 |
body=typing.cast( |
| 325 |
typing.Any, |
| 326 |
parse_obj_as( |
| 327 |
type_=typing.Any, |
| 328 |
object_=_response.json(), |
| 329 |
), |
| 330 |
), |
| 331 |
) |
| 332 |
if _response.status_code == 403: |
| 333 |
raise ForbiddenError( |
| 334 |
headers=dict(_response.headers), |
| 335 |
body=typing.cast( |
| 336 |
typing.Any, |
| 337 |
parse_obj_as( |
| 338 |
type_=typing.Any, |
| 339 |
object_=_response.json(), |
| 340 |
), |
| 341 |
), |
| 342 |
) |
| 343 |
_response_json = _response.json() |
| 344 |
except JSONDecodeError: |
| 345 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 346 |
except ValidationError as e: |
| 347 |
raise ParsingError( |
| 348 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 349 |
) |
| 350 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |