| 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 ..errors.bad_request_error import BadRequestError |
| 15 |
from ..errors.conflict_error import ConflictError |
| 16 |
from ..errors.forbidden_error import ForbiddenError |
| 17 |
from ..errors.not_found_error import NotFoundError |
| 18 |
from ..errors.service_unavailable_error import ServiceUnavailableError |
| 19 |
from ..errors.too_many_requests_error import TooManyRequestsError |
| 20 |
from ..errors.unauthorized_error import UnauthorizedError |
| 21 |
from ..types.app_metadata import AppMetadata |
| 22 |
from ..types.create_user_response_content import CreateUserResponseContent |
| 23 |
from ..types.get_user_response_content import GetUserResponseContent |
| 24 |
from ..types.list_users_offset_paginated_response_content import ListUsersOffsetPaginatedResponseContent |
| 25 |
from ..types.regenerate_users_recovery_code_response_content import RegenerateUsersRecoveryCodeResponseContent |
| 26 |
from ..types.search_engine_versions_enum import SearchEngineVersionsEnum |
| 27 |
from ..types.update_user_response_content import UpdateUserResponseContent |
| 28 |
from ..types.user_metadata import UserMetadata |
| 29 |
from ..types.user_response_schema import UserResponseSchema |
| 30 |
from pydantic import ValidationError |
| 31 |
|
| 32 |
|
| 33 |
OMIT = typing.cast(typing.Any, ...) |
| 34 |
|
| 35 |
|
| 36 |
class RawUsersClient: |
| 37 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 38 |
self._client_wrapper = client_wrapper |
| 39 |
|
| 40 |
def list( |
| 41 |
self, |
| 42 |
*, |
| 43 |
page: typing.Optional[int] = 0, |
| 44 |
per_page: typing.Optional[int] = 50, |
| 45 |
include_totals: typing.Optional[bool] = True, |
| 46 |
sort: typing.Optional[str] = None, |
| 47 |
connection: typing.Optional[str] = None, |
| 48 |
fields: typing.Optional[str] = None, |
| 49 |
include_fields: typing.Optional[bool] = None, |
| 50 |
q: typing.Optional[str] = None, |
| 51 |
search_engine: typing.Optional[SearchEngineVersionsEnum] = None, |
| 52 |
primary_order: typing.Optional[bool] = None, |
| 53 |
request_options: typing.Optional[RequestOptions] = None, |
| 54 |
) -> SyncPager[UserResponseSchema, ListUsersOffsetPaginatedResponseContent]: |
| 55 |
""" |
| 56 |
Retrieve details of users. It is possible to: |
| 57 |
|
| 58 |
- Specify a search criteria for users |
| 59 |
- Sort the users to be returned |
| 60 |
- Select the fields to be returned |
| 61 |
- Specify the number of users to retrieve per page and the page index |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
The `q` query parameter can be used to get users that match the specified criteria [using query string syntax.](https://auth0.com/docs/users/search/v3/query-syntax) |
| 66 |
|
| 67 |
[Learn more about searching for users.](https://auth0.com/docs/users/search/v3) |
| 68 |
|
| 69 |
Read about [best practices](https://auth0.com/docs/users/search/best-practices) when working with the API endpoints for retrieving users. |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
Auth0 limits the number of users you can return. If you exceed this threshold, please redefine your search, use the [export job](https://auth0.com/docs/api/management/v2#!/Jobs/post_users_exports), or the [User Import / Export](https://auth0.com/docs/extensions/user-import-export) extension. |
| 74 |
|
| 75 |
Parameters |
| 76 |
---------- |
| 77 |
page : typing.Optional[int] |
| 78 |
Page index of the results to return. First page is 0. |
| 79 |
|
| 80 |
per_page : typing.Optional[int] |
| 81 |
Number of results per page. |
| 82 |
|
| 83 |
include_totals : typing.Optional[bool] |
| 84 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 85 |
|
| 86 |
sort : typing.Optional[str] |
| 87 |
Field to sort by. Use <code>field:order</code> where order is <code>1</code> for ascending and <code>-1</code> for descending. e.g. <code>created_at:1</code> |
| 88 |
|
| 89 |
connection : typing.Optional[str] |
| 90 |
Connection filter. Only applies when using <code>search_engine=v1</code>. To filter by connection with <code>search_engine=v2|v3</code>, use <code>q=identities.connection:"connection_name"</code> |
| 91 |
|
| 92 |
fields : typing.Optional[str] |
| 93 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 94 |
|
| 95 |
include_fields : typing.Optional[bool] |
| 96 |
Whether specified fields are to be included (true) or excluded (false). |
| 97 |
|
| 98 |
q : typing.Optional[str] |
| 99 |
Query in <a target='_new' href ='https://lucene.apache.org/core/2_9_4/queryparsersyntax.html'>Lucene query string syntax</a>. Some query types cannot be used on metadata fields, for details see <a href='https://auth0.com/docs/users/search/v3/query-syntax#searchable-fields'>Searchable Fields</a>. |
| 100 |
|
| 101 |
search_engine : typing.Optional[SearchEngineVersionsEnum] |
| 102 |
The version of the search engine |
| 103 |
|
| 104 |
primary_order : typing.Optional[bool] |
| 105 |
If true (default), results are returned in a deterministic order. If false, results may be returned in a non-deterministic order, which can enhance performance for complex queries targeting a small number of users. Set to false only when consistent ordering and pagination is not required. |
| 106 |
|
| 107 |
request_options : typing.Optional[RequestOptions] |
| 108 |
Request-specific configuration. |
| 109 |
|
| 110 |
Returns |
| 111 |
------- |
| 112 |
SyncPager[UserResponseSchema, ListUsersOffsetPaginatedResponseContent] |
| 113 |
Users successfully retrieved. |
| 114 |
""" |
| 115 |
page = page if page is not None else 0 |
| 116 |
|
| 117 |
_response = self._client_wrapper.httpx_client.request( |
| 118 |
"users", |
| 119 |
method="GET", |
| 120 |
params={ |
| 121 |
"page": page, |
| 122 |
"per_page": per_page, |
| 123 |
"include_totals": include_totals, |
| 124 |
"sort": sort, |
| 125 |
"connection": connection, |
| 126 |
"fields": fields, |
| 127 |
"include_fields": include_fields, |
| 128 |
"q": q, |
| 129 |
"search_engine": search_engine, |
| 130 |
"primary_order": primary_order, |
| 131 |
}, |
| 132 |
request_options=request_options, |
| 133 |
) |
| 134 |
try: |
| 135 |
if 200 <= _response.status_code < 300: |
| 136 |
_parsed_response = typing.cast( |
| 137 |
ListUsersOffsetPaginatedResponseContent, |
| 138 |
parse_obj_as( |
| 139 |
type_=ListUsersOffsetPaginatedResponseContent, |
| 140 |
object_=_response.json(), |
| 141 |
), |
| 142 |
) |
| 143 |
_items = _parsed_response.users |
| 144 |
_has_next = len(_items or []) > 0 |
| 145 |
_get_next = lambda: self.list( |
| 146 |
page=page + 1, |
| 147 |
per_page=per_page, |
| 148 |
include_totals=include_totals, |
| 149 |
sort=sort, |
| 150 |
connection=connection, |
| 151 |
fields=fields, |
| 152 |
include_fields=include_fields, |
| 153 |
q=q, |
| 154 |
search_engine=search_engine, |
| 155 |
primary_order=primary_order, |
| 156 |
request_options=request_options, |
| 157 |
) |
| 158 |
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 159 |
if _response.status_code == 400: |
| 160 |
raise BadRequestError( |
| 161 |
headers=dict(_response.headers), |
| 162 |
body=typing.cast( |
| 163 |
typing.Any, |
| 164 |
parse_obj_as( |
| 165 |
type_=typing.Any, |
| 166 |
object_=_response.json(), |
| 167 |
), |
| 168 |
), |
| 169 |
) |
| 170 |
if _response.status_code == 401: |
| 171 |
raise UnauthorizedError( |
| 172 |
headers=dict(_response.headers), |
| 173 |
body=typing.cast( |
| 174 |
typing.Any, |
| 175 |
parse_obj_as( |
| 176 |
type_=typing.Any, |
| 177 |
object_=_response.json(), |
| 178 |
), |
| 179 |
), |
| 180 |
) |
| 181 |
if _response.status_code == 403: |
| 182 |
raise ForbiddenError( |
| 183 |
headers=dict(_response.headers), |
| 184 |
body=typing.cast( |
| 185 |
typing.Any, |
| 186 |
parse_obj_as( |
| 187 |
type_=typing.Any, |
| 188 |
object_=_response.json(), |
| 189 |
), |
| 190 |
), |
| 191 |
) |
| 192 |
if _response.status_code == 429: |
| 193 |
raise TooManyRequestsError( |
| 194 |
headers=dict(_response.headers), |
| 195 |
body=typing.cast( |
| 196 |
typing.Any, |
| 197 |
parse_obj_as( |
| 198 |
type_=typing.Any, |
| 199 |
object_=_response.json(), |
| 200 |
), |
| 201 |
), |
| 202 |
) |
| 203 |
if _response.status_code == 503: |
| 204 |
raise ServiceUnavailableError( |
| 205 |
headers=dict(_response.headers), |
| 206 |
body=typing.cast( |
| 207 |
typing.Any, |
| 208 |
parse_obj_as( |
| 209 |
type_=typing.Any, |
| 210 |
object_=_response.json(), |
| 211 |
), |
| 212 |
), |
| 213 |
) |
| 214 |
_response_json = _response.json() |
| 215 |
except JSONDecodeError: |
| 216 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 217 |
except ValidationError as e: |
| 218 |
raise ParsingError( |
| 219 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 220 |
) |
| 221 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 222 |
|
| 223 |
def create( |
| 224 |
self, |
| 225 |
*, |
| 226 |
connection: str, |
| 227 |
email: typing.Optional[str] = OMIT, |
| 228 |
phone_number: typing.Optional[str] = OMIT, |
| 229 |
user_metadata: typing.Optional[UserMetadata] = OMIT, |
| 230 |
blocked: typing.Optional[bool] = OMIT, |
| 231 |
email_verified: typing.Optional[bool] = OMIT, |
| 232 |
phone_verified: typing.Optional[bool] = OMIT, |
| 233 |
app_metadata: typing.Optional[AppMetadata] = OMIT, |
| 234 |
given_name: typing.Optional[str] = OMIT, |
| 235 |
family_name: typing.Optional[str] = OMIT, |
| 236 |
name: typing.Optional[str] = OMIT, |
| 237 |
nickname: typing.Optional[str] = OMIT, |
| 238 |
picture: typing.Optional[str] = OMIT, |
| 239 |
user_id: typing.Optional[str] = OMIT, |
| 240 |
password: typing.Optional[str] = OMIT, |
| 241 |
verify_email: typing.Optional[bool] = OMIT, |
| 242 |
username: typing.Optional[str] = OMIT, |
| 243 |
request_options: typing.Optional[RequestOptions] = None, |
| 244 |
) -> HttpResponse[CreateUserResponseContent]: |
| 245 |
""" |
| 246 |
Create a new user for a given [database](https://auth0.com/docs/connections/database) or [passwordless](https://auth0.com/docs/connections/passwordless) connection. |
| 247 |
|
| 248 |
Note: `connection` is required but other parameters such as `email` and `password` are dependent upon the type of connection. |
| 249 |
|
| 250 |
Parameters |
| 251 |
---------- |
| 252 |
connection : str |
| 253 |
Name of the connection this user should be created in. |
| 254 |
|
| 255 |
email : typing.Optional[str] |
| 256 |
The user's email. |
| 257 |
|
| 258 |
phone_number : typing.Optional[str] |
| 259 |
The user's phone number (following the E.164 recommendation). |
| 260 |
|
| 261 |
user_metadata : typing.Optional[UserMetadata] |
| 262 |
|
| 263 |
blocked : typing.Optional[bool] |
| 264 |
Whether this user was blocked by an administrator (true) or not (false). |
| 265 |
|
| 266 |
email_verified : typing.Optional[bool] |
| 267 |
Whether this email address is verified (true) or unverified (false). User will receive a verification email after creation if `email_verified` is false or not specified |
| 268 |
|
| 269 |
phone_verified : typing.Optional[bool] |
| 270 |
Whether this phone number has been verified (true) or not (false). |
| 271 |
|
| 272 |
app_metadata : typing.Optional[AppMetadata] |
| 273 |
|
| 274 |
given_name : typing.Optional[str] |
| 275 |
The user's given name(s). |
| 276 |
|
| 277 |
family_name : typing.Optional[str] |
| 278 |
The user's family name(s). |
| 279 |
|
| 280 |
name : typing.Optional[str] |
| 281 |
The user's full name. |
| 282 |
|
| 283 |
nickname : typing.Optional[str] |
| 284 |
The user's nickname. |
| 285 |
|
| 286 |
picture : typing.Optional[str] |
| 287 |
A URI pointing to the user's picture. |
| 288 |
|
| 289 |
user_id : typing.Optional[str] |
| 290 |
The external user's id provided by the identity provider. |
| 291 |
|
| 292 |
password : typing.Optional[str] |
| 293 |
Initial password for this user. Only valid for auth0 connection strategy. |
| 294 |
|
| 295 |
verify_email : typing.Optional[bool] |
| 296 |
Whether the user will receive a verification email after creation (true) or no email (false). Overrides behavior of `email_verified` parameter. |
| 297 |
|
| 298 |
username : typing.Optional[str] |
| 299 |
The user's username. Only valid if the connection requires a username. |
| 300 |
|
| 301 |
request_options : typing.Optional[RequestOptions] |
| 302 |
Request-specific configuration. |
| 303 |
|
| 304 |
Returns |
| 305 |
------- |
| 306 |
HttpResponse[CreateUserResponseContent] |
| 307 |
User successfully created. |
| 308 |
""" |
| 309 |
_response = self._client_wrapper.httpx_client.request( |
| 310 |
"users", |
| 311 |
method="POST", |
| 312 |
json={ |
| 313 |
"email": email, |
| 314 |
"phone_number": phone_number, |
| 315 |
"user_metadata": user_metadata, |
| 316 |
"blocked": blocked, |
| 317 |
"email_verified": email_verified, |
| 318 |
"phone_verified": phone_verified, |
| 319 |
"app_metadata": app_metadata, |
| 320 |
"given_name": given_name, |
| 321 |
"family_name": family_name, |
| 322 |
"name": name, |
| 323 |
"nickname": nickname, |
| 324 |
"picture": picture, |
| 325 |
"user_id": user_id, |
| 326 |
"connection": connection, |
| 327 |
"password": password, |
| 328 |
"verify_email": verify_email, |
| 329 |
"username": username, |
| 330 |
}, |
| 331 |
headers={ |
| 332 |
"content-type": "application/json", |
| 333 |
}, |
| 334 |
request_options=request_options, |
| 335 |
omit=OMIT, |
| 336 |
) |
| 337 |
try: |
| 338 |
if 200 <= _response.status_code < 300: |
| 339 |
_data = typing.cast( |
| 340 |
CreateUserResponseContent, |
| 341 |
parse_obj_as( |
| 342 |
type_=CreateUserResponseContent, |
| 343 |
object_=_response.json(), |
| 344 |
), |
| 345 |
) |
| 346 |
return HttpResponse(response=_response, data=_data) |
| 347 |
if _response.status_code == 400: |
| 348 |
raise BadRequestError( |
| 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 |
if _response.status_code == 401: |
| 359 |
raise UnauthorizedError( |
| 360 |
headers=dict(_response.headers), |
| 361 |
body=typing.cast( |
| 362 |
typing.Any, |
| 363 |
parse_obj_as( |
| 364 |
type_=typing.Any, |
| 365 |
object_=_response.json(), |
| 366 |
), |
| 367 |
), |
| 368 |
) |
| 369 |
if _response.status_code == 403: |
| 370 |
raise ForbiddenError( |
| 371 |
headers=dict(_response.headers), |
| 372 |
body=typing.cast( |
| 373 |
typing.Any, |
| 374 |
parse_obj_as( |
| 375 |
type_=typing.Any, |
| 376 |
object_=_response.json(), |
| 377 |
), |
| 378 |
), |
| 379 |
) |
| 380 |
if _response.status_code == 409: |
| 381 |
raise ConflictError( |
| 382 |
headers=dict(_response.headers), |
| 383 |
body=typing.cast( |
| 384 |
typing.Any, |
| 385 |
parse_obj_as( |
| 386 |
type_=typing.Any, |
| 387 |
object_=_response.json(), |
| 388 |
), |
| 389 |
), |
| 390 |
) |
| 391 |
if _response.status_code == 429: |
| 392 |
raise TooManyRequestsError( |
| 393 |
headers=dict(_response.headers), |
| 394 |
body=typing.cast( |
| 395 |
typing.Any, |
| 396 |
parse_obj_as( |
| 397 |
type_=typing.Any, |
| 398 |
object_=_response.json(), |
| 399 |
), |
| 400 |
), |
| 401 |
) |
| 402 |
_response_json = _response.json() |
| 403 |
except JSONDecodeError: |
| 404 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 405 |
except ValidationError as e: |
| 406 |
raise ParsingError( |
| 407 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 408 |
) |
| 409 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 410 |
|
| 411 |
def list_users_by_email( |
| 412 |
self, |
| 413 |
*, |
| 414 |
email: str, |
| 415 |
fields: typing.Optional[str] = None, |
| 416 |
include_fields: typing.Optional[bool] = None, |
| 417 |
request_options: typing.Optional[RequestOptions] = None, |
| 418 |
) -> HttpResponse[typing.List[UserResponseSchema]]: |
| 419 |
""" |
| 420 |
Find users by email. If Auth0 is the identity provider (idP), the email address associated with a user is saved in lower case, regardless of how you initially provided it. |
| 421 |
|
| 422 |
For example, if you register a user as [email protected], Auth0 saves the user's email as [email protected]. |
| 423 |
|
| 424 |
Therefore, when using this endpoint, make sure that you are searching for users via email addresses using the correct case. |
| 425 |
|
| 426 |
Parameters |
| 427 |
---------- |
| 428 |
email : str |
| 429 |
Email address to search for (case-sensitive). |
| 430 |
|
| 431 |
fields : typing.Optional[str] |
| 432 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 433 |
|
| 434 |
include_fields : typing.Optional[bool] |
| 435 |
Whether specified fields are to be included (true) or excluded (false). Defaults to true. |
| 436 |
|
| 437 |
request_options : typing.Optional[RequestOptions] |
| 438 |
Request-specific configuration. |
| 439 |
|
| 440 |
Returns |
| 441 |
------- |
| 442 |
HttpResponse[typing.List[UserResponseSchema]] |
| 443 |
Users successfully searched. |
| 444 |
""" |
| 445 |
_response = self._client_wrapper.httpx_client.request( |
| 446 |
"users-by-email", |
| 447 |
method="GET", |
| 448 |
params={ |
| 449 |
"fields": fields, |
| 450 |
"include_fields": include_fields, |
| 451 |
"email": email, |
| 452 |
}, |
| 453 |
request_options=request_options, |
| 454 |
) |
| 455 |
try: |
| 456 |
if 200 <= _response.status_code < 300: |
| 457 |
_data = typing.cast( |
| 458 |
typing.List[UserResponseSchema], |
| 459 |
parse_obj_as( |
| 460 |
type_=typing.List[UserResponseSchema], |
| 461 |
object_=_response.json(), |
| 462 |
), |
| 463 |
) |
| 464 |
return HttpResponse(response=_response, data=_data) |
| 465 |
if _response.status_code == 400: |
| 466 |
raise BadRequestError( |
| 467 |
headers=dict(_response.headers), |
| 468 |
body=typing.cast( |
| 469 |
typing.Any, |
| 470 |
parse_obj_as( |
| 471 |
type_=typing.Any, |
| 472 |
object_=_response.json(), |
| 473 |
), |
| 474 |
), |
| 475 |
) |
| 476 |
if _response.status_code == 401: |
| 477 |
raise UnauthorizedError( |
| 478 |
headers=dict(_response.headers), |
| 479 |
body=typing.cast( |
| 480 |
typing.Any, |
| 481 |
parse_obj_as( |
| 482 |
type_=typing.Any, |
| 483 |
object_=_response.json(), |
| 484 |
), |
| 485 |
), |
| 486 |
) |
| 487 |
if _response.status_code == 403: |
| 488 |
raise ForbiddenError( |
| 489 |
headers=dict(_response.headers), |
| 490 |
body=typing.cast( |
| 491 |
typing.Any, |
| 492 |
parse_obj_as( |
| 493 |
type_=typing.Any, |
| 494 |
object_=_response.json(), |
| 495 |
), |
| 496 |
), |
| 497 |
) |
| 498 |
if _response.status_code == 429: |
| 499 |
raise TooManyRequestsError( |
| 500 |
headers=dict(_response.headers), |
| 501 |
body=typing.cast( |
| 502 |
typing.Any, |
| 503 |
parse_obj_as( |
| 504 |
type_=typing.Any, |
| 505 |
object_=_response.json(), |
| 506 |
), |
| 507 |
), |
| 508 |
) |
| 509 |
_response_json = _response.json() |
| 510 |
except JSONDecodeError: |
| 511 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 512 |
except ValidationError as e: |
| 513 |
raise ParsingError( |
| 514 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 515 |
) |
| 516 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 517 |
|
| 518 |
def get( |
| 519 |
self, |
| 520 |
id: str, |
| 521 |
*, |
| 522 |
fields: typing.Optional[str] = None, |
| 523 |
include_fields: typing.Optional[bool] = None, |
| 524 |
request_options: typing.Optional[RequestOptions] = None, |
| 525 |
) -> HttpResponse[GetUserResponseContent]: |
| 526 |
""" |
| 527 |
Retrieve user details. A list of fields to include or exclude may also be specified. For more information, see [Retrieve Users with the Get Users Endpoint](https://auth0.com/docs/manage-users/user-search/retrieve-users-with-get-users-endpoint). |
| 528 |
|
| 529 |
Parameters |
| 530 |
---------- |
| 531 |
id : str |
| 532 |
ID of the user to retrieve. |
| 533 |
|
| 534 |
fields : typing.Optional[str] |
| 535 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 536 |
|
| 537 |
include_fields : typing.Optional[bool] |
| 538 |
Whether specified fields are to be included (true) or excluded (false). |
| 539 |
|
| 540 |
request_options : typing.Optional[RequestOptions] |
| 541 |
Request-specific configuration. |
| 542 |
|
| 543 |
Returns |
| 544 |
------- |
| 545 |
HttpResponse[GetUserResponseContent] |
| 546 |
User successfully retrieved. |
| 547 |
""" |
| 548 |
_response = self._client_wrapper.httpx_client.request( |
| 549 |
f"users/{encode_path_param(id)}", |
| 550 |
method="GET", |
| 551 |
params={ |
| 552 |
"fields": fields, |
| 553 |
"include_fields": include_fields, |
| 554 |
}, |
| 555 |
request_options=request_options, |
| 556 |
) |
| 557 |
try: |
| 558 |
if 200 <= _response.status_code < 300: |
| 559 |
_data = typing.cast( |
| 560 |
GetUserResponseContent, |
| 561 |
parse_obj_as( |
| 562 |
type_=GetUserResponseContent, |
| 563 |
object_=_response.json(), |
| 564 |
), |
| 565 |
) |
| 566 |
return HttpResponse(response=_response, data=_data) |
| 567 |
if _response.status_code == 400: |
| 568 |
raise BadRequestError( |
| 569 |
headers=dict(_response.headers), |
| 570 |
body=typing.cast( |
| 571 |
typing.Any, |
| 572 |
parse_obj_as( |
| 573 |
type_=typing.Any, |
| 574 |
object_=_response.json(), |
| 575 |
), |
| 576 |
), |
| 577 |
) |
| 578 |
if _response.status_code == 401: |
| 579 |
raise UnauthorizedError( |
| 580 |
headers=dict(_response.headers), |
| 581 |
body=typing.cast( |
| 582 |
typing.Any, |
| 583 |
parse_obj_as( |
| 584 |
type_=typing.Any, |
| 585 |
object_=_response.json(), |
| 586 |
), |
| 587 |
), |
| 588 |
) |
| 589 |
if _response.status_code == 403: |
| 590 |
raise ForbiddenError( |
| 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 == 404: |
| 601 |
raise NotFoundError( |
| 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 == 429: |
| 612 |
raise TooManyRequestsError( |
| 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 |
_response_json = _response.json() |
| 623 |
except JSONDecodeError: |
| 624 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 625 |
except ValidationError as e: |
| 626 |
raise ParsingError( |
| 627 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 628 |
) |
| 629 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 630 |
|
| 631 |
def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]: |
| 632 |
""" |
| 633 |
Delete a user by user ID. This action cannot be undone. For Auth0 Dashboard instructions, see [Delete Users](https://auth0.com/docs/manage-users/user-accounts/delete-users). |
| 634 |
|
| 635 |
Parameters |
| 636 |
---------- |
| 637 |
id : str |
| 638 |
ID of the user to delete. |
| 639 |
|
| 640 |
request_options : typing.Optional[RequestOptions] |
| 641 |
Request-specific configuration. |
| 642 |
|
| 643 |
Returns |
| 644 |
------- |
| 645 |
HttpResponse[None] |
| 646 |
""" |
| 647 |
_response = self._client_wrapper.httpx_client.request( |
| 648 |
f"users/{encode_path_param(id)}", |
| 649 |
method="DELETE", |
| 650 |
request_options=request_options, |
| 651 |
) |
| 652 |
try: |
| 653 |
if 200 <= _response.status_code < 300: |
| 654 |
return HttpResponse(response=_response, data=None) |
| 655 |
if _response.status_code == 400: |
| 656 |
raise BadRequestError( |
| 657 |
headers=dict(_response.headers), |
| 658 |
body=typing.cast( |
| 659 |
typing.Any, |
| 660 |
parse_obj_as( |
| 661 |
type_=typing.Any, |
| 662 |
object_=_response.json(), |
| 663 |
), |
| 664 |
), |
| 665 |
) |
| 666 |
if _response.status_code == 401: |
| 667 |
raise UnauthorizedError( |
| 668 |
headers=dict(_response.headers), |
| 669 |
body=typing.cast( |
| 670 |
typing.Any, |
| 671 |
parse_obj_as( |
| 672 |
type_=typing.Any, |
| 673 |
object_=_response.json(), |
| 674 |
), |
| 675 |
), |
| 676 |
) |
| 677 |
if _response.status_code == 403: |
| 678 |
raise ForbiddenError( |
| 679 |
headers=dict(_response.headers), |
| 680 |
body=typing.cast( |
| 681 |
typing.Any, |
| 682 |
parse_obj_as( |
| 683 |
type_=typing.Any, |
| 684 |
object_=_response.json(), |
| 685 |
), |
| 686 |
), |
| 687 |
) |
| 688 |
if _response.status_code == 429: |
| 689 |
raise TooManyRequestsError( |
| 690 |
headers=dict(_response.headers), |
| 691 |
body=typing.cast( |
| 692 |
typing.Any, |
| 693 |
parse_obj_as( |
| 694 |
type_=typing.Any, |
| 695 |
object_=_response.json(), |
| 696 |
), |
| 697 |
), |
| 698 |
) |
| 699 |
_response_json = _response.json() |
| 700 |
except JSONDecodeError: |
| 701 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 702 |
except ValidationError as e: |
| 703 |
raise ParsingError( |
| 704 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 705 |
) |
| 706 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 707 |
|
| 708 |
def update( |
| 709 |
self, |
| 710 |
id: str, |
| 711 |
*, |
| 712 |
blocked: typing.Optional[bool] = OMIT, |
| 713 |
email_verified: typing.Optional[bool] = OMIT, |
| 714 |
email: typing.Optional[str] = OMIT, |
| 715 |
phone_number: typing.Optional[str] = OMIT, |
| 716 |
phone_verified: typing.Optional[bool] = OMIT, |
| 717 |
user_metadata: typing.Optional[UserMetadata] = OMIT, |
| 718 |
app_metadata: typing.Optional[AppMetadata] = OMIT, |
| 719 |
given_name: typing.Optional[str] = OMIT, |
| 720 |
family_name: typing.Optional[str] = OMIT, |
| 721 |
name: typing.Optional[str] = OMIT, |
| 722 |
nickname: typing.Optional[str] = OMIT, |
| 723 |
picture: typing.Optional[str] = OMIT, |
| 724 |
verify_email: typing.Optional[bool] = OMIT, |
| 725 |
verify_phone_number: typing.Optional[bool] = OMIT, |
| 726 |
password: typing.Optional[str] = OMIT, |
| 727 |
connection: typing.Optional[str] = OMIT, |
| 728 |
client_id: typing.Optional[str] = OMIT, |
| 729 |
username: typing.Optional[str] = OMIT, |
| 730 |
request_options: typing.Optional[RequestOptions] = None, |
| 731 |
) -> HttpResponse[UpdateUserResponseContent]: |
| 732 |
""" |
| 733 |
Update a user. |
| 734 |
|
| 735 |
These are the attributes that can be updated at the root level: |
| 736 |
|
| 737 |
- app_metadata |
| 738 |
- blocked |
| 739 |
- email |
| 740 |
- email_verified |
| 741 |
- family_name |
| 742 |
- given_name |
| 743 |
- name |
| 744 |
- nickname |
| 745 |
- password |
| 746 |
- phone_number |
| 747 |
- phone_verified |
| 748 |
- picture |
| 749 |
- username |
| 750 |
- user_metadata |
| 751 |
- verify_email |
| 752 |
|
| 753 |
Some considerations: |
| 754 |
|
| 755 |
- The properties of the new object will replace the old ones. |
| 756 |
- The metadata fields are an exception to this rule (`user_metadata` and `app_metadata`). These properties are merged instead of being replaced but be careful, the merge only occurs on the first level. |
| 757 |
- If you are updating `email`, `email_verified`, `phone_number`, `phone_verified`, `username` or `password` of a secondary identity, you need to specify the `connection` property too. |
| 758 |
- If you are updating `email` or `phone_number` you can specify, optionally, the `client_id` property. |
| 759 |
- Updating `email_verified` is not supported for enterprise and passwordless sms connections. |
| 760 |
- Updating the `blocked` to `false` does not affect the user's blocked state from an excessive amount of incorrectly provided credentials. Use the "Unblock a user" endpoint from the "User Blocks" API to change the user's state. |
| 761 |
- Supported attributes can be unset by supplying `null` as the value. |
| 762 |
|
| 763 |
**Updating a field (non-metadata property)** |
| 764 |
|
| 765 |
To mark the email address of a user as verified, the body to send should be: |
| 766 |
|
| 767 |
```json |
| 768 |
{ "email_verified": true } |
| 769 |
``` |
| 770 |
|
| 771 |
**Updating a user metadata root property** |
| 772 |
|
| 773 |
Let's assume that our test user has the following `user_metadata`: |
| 774 |
|
| 775 |
```json |
| 776 |
{ "user_metadata" : { "profileCode": 1479 } } |
| 777 |
``` |
| 778 |
|
| 779 |
To add the field `addresses` the body to send should be: |
| 780 |
|
| 781 |
```json |
| 782 |
{ "user_metadata" : { "addresses": {"work_address": "100 Industrial Way"} }} |
| 783 |
``` |
| 784 |
|
| 785 |
The modified object ends up with the following `user_metadata` property: |
| 786 |
|
| 787 |
```json |
| 788 |
{ |
| 789 |
"user_metadata": { |
| 790 |
"profileCode": 1479, |
| 791 |
"addresses": { "work_address": "100 Industrial Way" } |
| 792 |
} |
| 793 |
} |
| 794 |
``` |
| 795 |
|
| 796 |
**Updating an inner user metadata property** |
| 797 |
|
| 798 |
If there's existing user metadata to which we want to add `"home_address": "742 Evergreen Terrace"` (using the `addresses` property) we should send the whole `addresses` object. Since this is a first-level object, the object will be merged in, but its own properties will not be. The body to send should be: |
| 799 |
|
| 800 |
```json |
| 801 |
{ |
| 802 |
"user_metadata": { |
| 803 |
"addresses": { |
| 804 |
"work_address": "100 Industrial Way", |
| 805 |
"home_address": "742 Evergreen Terrace" |
| 806 |
} |
| 807 |
} |
| 808 |
} |
| 809 |
``` |
| 810 |
|
| 811 |
The modified object ends up with the following `user_metadata` property: |
| 812 |
|
| 813 |
```json |
| 814 |
{ |
| 815 |
"user_metadata": { |
| 816 |
"profileCode": 1479, |
| 817 |
"addresses": { |
| 818 |
"work_address": "100 Industrial Way", |
| 819 |
"home_address": "742 Evergreen Terrace" |
| 820 |
} |
| 821 |
} |
| 822 |
} |
| 823 |
``` |
| 824 |
|
| 825 |
Parameters |
| 826 |
---------- |
| 827 |
id : str |
| 828 |
ID of the user to update. |
| 829 |
|
| 830 |
blocked : typing.Optional[bool] |
| 831 |
Whether this user was blocked by an administrator (true) or not (false). |
| 832 |
|
| 833 |
email_verified : typing.Optional[bool] |
| 834 |
Whether this email address is verified (true) or unverified (false). If set to false the user will not receive a verification email unless `verify_email` is set to true. |
| 835 |
|
| 836 |
email : typing.Optional[str] |
| 837 |
Email address of this user. |
| 838 |
|
| 839 |
phone_number : typing.Optional[str] |
| 840 |
The user's phone number (following the E.164 recommendation). |
| 841 |
|
| 842 |
phone_verified : typing.Optional[bool] |
| 843 |
Whether this phone number has been verified (true) or not (false). |
| 844 |
|
| 845 |
user_metadata : typing.Optional[UserMetadata] |
| 846 |
User metadata to which this user has read/write access. |
| 847 |
|
| 848 |
app_metadata : typing.Optional[AppMetadata] |
| 849 |
User metadata to which this user has read-only access. |
| 850 |
|
| 851 |
given_name : typing.Optional[str] |
| 852 |
Given name/first name/forename of this user. |
| 853 |
|
| 854 |
family_name : typing.Optional[str] |
| 855 |
Family name/last name/surname of this user. |
| 856 |
|
| 857 |
name : typing.Optional[str] |
| 858 |
Name of this user. |
| 859 |
|
| 860 |
nickname : typing.Optional[str] |
| 861 |
Preferred nickname or alias of this user. |
| 862 |
|
| 863 |
picture : typing.Optional[str] |
| 864 |
URL to picture, photo, or avatar of this user. |
| 865 |
|
| 866 |
verify_email : typing.Optional[bool] |
| 867 |
Whether this user will receive a verification email after creation (true) or no email (false). Overrides behavior of `email_verified` parameter. |
| 868 |
|
| 869 |
verify_phone_number : typing.Optional[bool] |
| 870 |
Whether this user will receive a text after changing the phone number (true) or no text (false). Only valid when changing phone number for SMS connections. |
| 871 |
|
| 872 |
password : typing.Optional[str] |
| 873 |
New password for this user. Only valid for database connections. |
| 874 |
|
| 875 |
connection : typing.Optional[str] |
| 876 |
Name of the connection to target for this user update. |
| 877 |
|
| 878 |
client_id : typing.Optional[str] |
| 879 |
Auth0 client ID. Only valid when updating email address. |
| 880 |
|
| 881 |
username : typing.Optional[str] |
| 882 |
The user's username. Only valid if the connection requires a username. |
| 883 |
|
| 884 |
request_options : typing.Optional[RequestOptions] |
| 885 |
Request-specific configuration. |
| 886 |
|
| 887 |
Returns |
| 888 |
------- |
| 889 |
HttpResponse[UpdateUserResponseContent] |
| 890 |
User successfully updated. |
| 891 |
""" |
| 892 |
_response = self._client_wrapper.httpx_client.request( |
| 893 |
f"users/{encode_path_param(id)}", |
| 894 |
method="PATCH", |
| 895 |
json={ |
| 896 |
"blocked": blocked, |
| 897 |
"email_verified": email_verified, |
| 898 |
"email": email, |
| 899 |
"phone_number": phone_number, |
| 900 |
"phone_verified": phone_verified, |
| 901 |
"user_metadata": user_metadata, |
| 902 |
"app_metadata": app_metadata, |
| 903 |
"given_name": given_name, |
| 904 |
"family_name": family_name, |
| 905 |
"name": name, |
| 906 |
"nickname": nickname, |
| 907 |
"picture": picture, |
| 908 |
"verify_email": verify_email, |
| 909 |
"verify_phone_number": verify_phone_number, |
| 910 |
"password": password, |
| 911 |
"connection": connection, |
| 912 |
"client_id": client_id, |
| 913 |
"username": username, |
| 914 |
}, |
| 915 |
headers={ |
| 916 |
"content-type": "application/json", |
| 917 |
}, |
| 918 |
request_options=request_options, |
| 919 |
omit=OMIT, |
| 920 |
) |
| 921 |
try: |
| 922 |
if 200 <= _response.status_code < 300: |
| 923 |
_data = typing.cast( |
| 924 |
UpdateUserResponseContent, |
| 925 |
parse_obj_as( |
| 926 |
type_=UpdateUserResponseContent, |
| 927 |
object_=_response.json(), |
| 928 |
), |
| 929 |
) |
| 930 |
return HttpResponse(response=_response, data=_data) |
| 931 |
if _response.status_code == 400: |
| 932 |
raise BadRequestError( |
| 933 |
headers=dict(_response.headers), |
| 934 |
body=typing.cast( |
| 935 |
typing.Any, |
| 936 |
parse_obj_as( |
| 937 |
type_=typing.Any, |
| 938 |
object_=_response.json(), |
| 939 |
), |
| 940 |
), |
| 941 |
) |
| 942 |
if _response.status_code == 401: |
| 943 |
raise UnauthorizedError( |
| 944 |
headers=dict(_response.headers), |
| 945 |
body=typing.cast( |
| 946 |
typing.Any, |
| 947 |
parse_obj_as( |
| 948 |
type_=typing.Any, |
| 949 |
object_=_response.json(), |
| 950 |
), |
| 951 |
), |
| 952 |
) |
| 953 |
if _response.status_code == 403: |
| 954 |
raise ForbiddenError( |
| 955 |
headers=dict(_response.headers), |
| 956 |
body=typing.cast( |
| 957 |
typing.Any, |
| 958 |
parse_obj_as( |
| 959 |
type_=typing.Any, |
| 960 |
object_=_response.json(), |
| 961 |
), |
| 962 |
), |
| 963 |
) |
| 964 |
if _response.status_code == 404: |
| 965 |
raise NotFoundError( |
| 966 |
headers=dict(_response.headers), |
| 967 |
body=typing.cast( |
| 968 |
typing.Any, |
| 969 |
parse_obj_as( |
| 970 |
type_=typing.Any, |
| 971 |
object_=_response.json(), |
| 972 |
), |
| 973 |
), |
| 974 |
) |
| 975 |
if _response.status_code == 429: |
| 976 |
raise TooManyRequestsError( |
| 977 |
headers=dict(_response.headers), |
| 978 |
body=typing.cast( |
| 979 |
typing.Any, |
| 980 |
parse_obj_as( |
| 981 |
type_=typing.Any, |
| 982 |
object_=_response.json(), |
| 983 |
), |
| 984 |
), |
| 985 |
) |
| 986 |
_response_json = _response.json() |
| 987 |
except JSONDecodeError: |
| 988 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 989 |
except ValidationError as e: |
| 990 |
raise ParsingError( |
| 991 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 992 |
) |
| 993 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 994 |
|
| 995 |
def regenerate_recovery_code( |
| 996 |
self, id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 997 |
) -> HttpResponse[RegenerateUsersRecoveryCodeResponseContent]: |
| 998 |
""" |
| 999 |
Remove an existing multi-factor authentication (MFA) [recovery code](https://auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa) and generate a new one. If a user cannot access the original device or account used for MFA enrollment, they can use a recovery code to authenticate. |
| 1000 |
|
| 1001 |
Parameters |
| 1002 |
---------- |
| 1003 |
id : str |
| 1004 |
ID of the user to regenerate a multi-factor authentication recovery code for. |
| 1005 |
|
| 1006 |
request_options : typing.Optional[RequestOptions] |
| 1007 |
Request-specific configuration. |
| 1008 |
|
| 1009 |
Returns |
| 1010 |
------- |
| 1011 |
HttpResponse[RegenerateUsersRecoveryCodeResponseContent] |
| 1012 |
New recovery code successfully generated. |
| 1013 |
""" |
| 1014 |
_response = self._client_wrapper.httpx_client.request( |
| 1015 |
f"users/{encode_path_param(id)}/recovery-code-regeneration", |
| 1016 |
method="POST", |
| 1017 |
request_options=request_options, |
| 1018 |
) |
| 1019 |
try: |
| 1020 |
if 200 <= _response.status_code < 300: |
| 1021 |
_data = typing.cast( |
| 1022 |
RegenerateUsersRecoveryCodeResponseContent, |
| 1023 |
parse_obj_as( |
| 1024 |
type_=RegenerateUsersRecoveryCodeResponseContent, |
| 1025 |
object_=_response.json(), |
| 1026 |
), |
| 1027 |
) |
| 1028 |
return HttpResponse(response=_response, data=_data) |
| 1029 |
if _response.status_code == 400: |
| 1030 |
raise BadRequestError( |
| 1031 |
headers=dict(_response.headers), |
| 1032 |
body=typing.cast( |
| 1033 |
typing.Any, |
| 1034 |
parse_obj_as( |
| 1035 |
type_=typing.Any, |
| 1036 |
object_=_response.json(), |
| 1037 |
), |
| 1038 |
), |
| 1039 |
) |
| 1040 |
if _response.status_code == 401: |
| 1041 |
raise UnauthorizedError( |
| 1042 |
headers=dict(_response.headers), |
| 1043 |
body=typing.cast( |
| 1044 |
typing.Any, |
| 1045 |
parse_obj_as( |
| 1046 |
type_=typing.Any, |
| 1047 |
object_=_response.json(), |
| 1048 |
), |
| 1049 |
), |
| 1050 |
) |
| 1051 |
if _response.status_code == 403: |
| 1052 |
raise ForbiddenError( |
| 1053 |
headers=dict(_response.headers), |
| 1054 |
body=typing.cast( |
| 1055 |
typing.Any, |
| 1056 |
parse_obj_as( |
| 1057 |
type_=typing.Any, |
| 1058 |
object_=_response.json(), |
| 1059 |
), |
| 1060 |
), |
| 1061 |
) |
| 1062 |
if _response.status_code == 404: |
| 1063 |
raise NotFoundError( |
| 1064 |
headers=dict(_response.headers), |
| 1065 |
body=typing.cast( |
| 1066 |
typing.Any, |
| 1067 |
parse_obj_as( |
| 1068 |
type_=typing.Any, |
| 1069 |
object_=_response.json(), |
| 1070 |
), |
| 1071 |
), |
| 1072 |
) |
| 1073 |
_response_json = _response.json() |
| 1074 |
except JSONDecodeError: |
| 1075 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1076 |
except ValidationError as e: |
| 1077 |
raise ParsingError( |
| 1078 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1079 |
) |
| 1080 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1081 |
|
| 1082 |
def revoke_access( |
| 1083 |
self, |
| 1084 |
id: str, |
| 1085 |
*, |
| 1086 |
session_id: typing.Optional[str] = OMIT, |
| 1087 |
preserve_refresh_tokens: typing.Optional[bool] = OMIT, |
| 1088 |
request_options: typing.Optional[RequestOptions] = None, |
| 1089 |
) -> HttpResponse[None]: |
| 1090 |
""" |
| 1091 |
Revokes selected resources related to a user (sessions, refresh tokens, ...). |
| 1092 |
|
| 1093 |
Parameters |
| 1094 |
---------- |
| 1095 |
id : str |
| 1096 |
ID of the user. |
| 1097 |
|
| 1098 |
session_id : typing.Optional[str] |
| 1099 |
ID of the session to revoke. |
| 1100 |
|
| 1101 |
preserve_refresh_tokens : typing.Optional[bool] |
| 1102 |
Whether to preserve the refresh tokens associated with the session. |
| 1103 |
|
| 1104 |
request_options : typing.Optional[RequestOptions] |
| 1105 |
Request-specific configuration. |
| 1106 |
|
| 1107 |
Returns |
| 1108 |
------- |
| 1109 |
HttpResponse[None] |
| 1110 |
""" |
| 1111 |
_response = self._client_wrapper.httpx_client.request( |
| 1112 |
f"users/{encode_path_param(id)}/revoke-access", |
| 1113 |
method="POST", |
| 1114 |
json={ |
| 1115 |
"session_id": session_id, |
| 1116 |
"preserve_refresh_tokens": preserve_refresh_tokens, |
| 1117 |
}, |
| 1118 |
headers={ |
| 1119 |
"content-type": "application/json", |
| 1120 |
}, |
| 1121 |
request_options=request_options, |
| 1122 |
omit=OMIT, |
| 1123 |
) |
| 1124 |
try: |
| 1125 |
if 200 <= _response.status_code < 300: |
| 1126 |
return HttpResponse(response=_response, data=None) |
| 1127 |
if _response.status_code == 400: |
| 1128 |
raise BadRequestError( |
| 1129 |
headers=dict(_response.headers), |
| 1130 |
body=typing.cast( |
| 1131 |
typing.Any, |
| 1132 |
parse_obj_as( |
| 1133 |
type_=typing.Any, |
| 1134 |
object_=_response.json(), |
| 1135 |
), |
| 1136 |
), |
| 1137 |
) |
| 1138 |
if _response.status_code == 401: |
| 1139 |
raise UnauthorizedError( |
| 1140 |
headers=dict(_response.headers), |
| 1141 |
body=typing.cast( |
| 1142 |
typing.Any, |
| 1143 |
parse_obj_as( |
| 1144 |
type_=typing.Any, |
| 1145 |
object_=_response.json(), |
| 1146 |
), |
| 1147 |
), |
| 1148 |
) |
| 1149 |
if _response.status_code == 403: |
| 1150 |
raise ForbiddenError( |
| 1151 |
headers=dict(_response.headers), |
| 1152 |
body=typing.cast( |
| 1153 |
typing.Any, |
| 1154 |
parse_obj_as( |
| 1155 |
type_=typing.Any, |
| 1156 |
object_=_response.json(), |
| 1157 |
), |
| 1158 |
), |
| 1159 |
) |
| 1160 |
if _response.status_code == 429: |
| 1161 |
raise TooManyRequestsError( |
| 1162 |
headers=dict(_response.headers), |
| 1163 |
body=typing.cast( |
| 1164 |
typing.Any, |
| 1165 |
parse_obj_as( |
| 1166 |
type_=typing.Any, |
| 1167 |
object_=_response.json(), |
| 1168 |
), |
| 1169 |
), |
| 1170 |
) |
| 1171 |
_response_json = _response.json() |
| 1172 |
except JSONDecodeError: |
| 1173 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1174 |
except ValidationError as e: |
| 1175 |
raise ParsingError( |
| 1176 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1177 |
) |
| 1178 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1179 |
|
| 1180 |
|
| 1181 |
class AsyncRawUsersClient: |
| 1182 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 1183 |
self._client_wrapper = client_wrapper |
| 1184 |
|
| 1185 |
async def list( |
| 1186 |
self, |
| 1187 |
*, |
| 1188 |
page: typing.Optional[int] = 0, |
| 1189 |
per_page: typing.Optional[int] = 50, |
| 1190 |
include_totals: typing.Optional[bool] = True, |
| 1191 |
sort: typing.Optional[str] = None, |
| 1192 |
connection: typing.Optional[str] = None, |
| 1193 |
fields: typing.Optional[str] = None, |
| 1194 |
include_fields: typing.Optional[bool] = None, |
| 1195 |
q: typing.Optional[str] = None, |
| 1196 |
search_engine: typing.Optional[SearchEngineVersionsEnum] = None, |
| 1197 |
primary_order: typing.Optional[bool] = None, |
| 1198 |
request_options: typing.Optional[RequestOptions] = None, |
| 1199 |
) -> AsyncPager[UserResponseSchema, ListUsersOffsetPaginatedResponseContent]: |
| 1200 |
""" |
| 1201 |
Retrieve details of users. It is possible to: |
| 1202 |
|
| 1203 |
- Specify a search criteria for users |
| 1204 |
- Sort the users to be returned |
| 1205 |
- Select the fields to be returned |
| 1206 |
- Specify the number of users to retrieve per page and the page index |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
The `q` query parameter can be used to get users that match the specified criteria [using query string syntax.](https://auth0.com/docs/users/search/v3/query-syntax) |
| 1211 |
|
| 1212 |
[Learn more about searching for users.](https://auth0.com/docs/users/search/v3) |
| 1213 |
|
| 1214 |
Read about [best practices](https://auth0.com/docs/users/search/best-practices) when working with the API endpoints for retrieving users. |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
Auth0 limits the number of users you can return. If you exceed this threshold, please redefine your search, use the [export job](https://auth0.com/docs/api/management/v2#!/Jobs/post_users_exports), or the [User Import / Export](https://auth0.com/docs/extensions/user-import-export) extension. |
| 1219 |
|
| 1220 |
Parameters |
| 1221 |
---------- |
| 1222 |
page : typing.Optional[int] |
| 1223 |
Page index of the results to return. First page is 0. |
| 1224 |
|
| 1225 |
per_page : typing.Optional[int] |
| 1226 |
Number of results per page. |
| 1227 |
|
| 1228 |
include_totals : typing.Optional[bool] |
| 1229 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 1230 |
|
| 1231 |
sort : typing.Optional[str] |
| 1232 |
Field to sort by. Use <code>field:order</code> where order is <code>1</code> for ascending and <code>-1</code> for descending. e.g. <code>created_at:1</code> |
| 1233 |
|
| 1234 |
connection : typing.Optional[str] |
| 1235 |
Connection filter. Only applies when using <code>search_engine=v1</code>. To filter by connection with <code>search_engine=v2|v3</code>, use <code>q=identities.connection:"connection_name"</code> |
| 1236 |
|
| 1237 |
fields : typing.Optional[str] |
| 1238 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 1239 |
|
| 1240 |
include_fields : typing.Optional[bool] |
| 1241 |
Whether specified fields are to be included (true) or excluded (false). |
| 1242 |
|
| 1243 |
q : typing.Optional[str] |
| 1244 |
Query in <a target='_new' href ='https://lucene.apache.org/core/2_9_4/queryparsersyntax.html'>Lucene query string syntax</a>. Some query types cannot be used on metadata fields, for details see <a href='https://auth0.com/docs/users/search/v3/query-syntax#searchable-fields'>Searchable Fields</a>. |
| 1245 |
|
| 1246 |
search_engine : typing.Optional[SearchEngineVersionsEnum] |
| 1247 |
The version of the search engine |
| 1248 |
|
| 1249 |
primary_order : typing.Optional[bool] |
| 1250 |
If true (default), results are returned in a deterministic order. If false, results may be returned in a non-deterministic order, which can enhance performance for complex queries targeting a small number of users. Set to false only when consistent ordering and pagination is not required. |
| 1251 |
|
| 1252 |
request_options : typing.Optional[RequestOptions] |
| 1253 |
Request-specific configuration. |
| 1254 |
|
| 1255 |
Returns |
| 1256 |
------- |
| 1257 |
AsyncPager[UserResponseSchema, ListUsersOffsetPaginatedResponseContent] |
| 1258 |
Users successfully retrieved. |
| 1259 |
""" |
| 1260 |
page = page if page is not None else 0 |
| 1261 |
|
| 1262 |
_response = await self._client_wrapper.httpx_client.request( |
| 1263 |
"users", |
| 1264 |
method="GET", |
| 1265 |
params={ |
| 1266 |
"page": page, |
| 1267 |
"per_page": per_page, |
| 1268 |
"include_totals": include_totals, |
| 1269 |
"sort": sort, |
| 1270 |
"connection": connection, |
| 1271 |
"fields": fields, |
| 1272 |
"include_fields": include_fields, |
| 1273 |
"q": q, |
| 1274 |
"search_engine": search_engine, |
| 1275 |
"primary_order": primary_order, |
| 1276 |
}, |
| 1277 |
request_options=request_options, |
| 1278 |
) |
| 1279 |
try: |
| 1280 |
if 200 <= _response.status_code < 300: |
| 1281 |
_parsed_response = typing.cast( |
| 1282 |
ListUsersOffsetPaginatedResponseContent, |
| 1283 |
parse_obj_as( |
| 1284 |
type_=ListUsersOffsetPaginatedResponseContent, |
| 1285 |
object_=_response.json(), |
| 1286 |
), |
| 1287 |
) |
| 1288 |
_items = _parsed_response.users |
| 1289 |
_has_next = len(_items or []) > 0 |
| 1290 |
|
| 1291 |
async def _get_next(): |
| 1292 |
return await self.list( |
| 1293 |
page=page + 1, |
| 1294 |
per_page=per_page, |
| 1295 |
include_totals=include_totals, |
| 1296 |
sort=sort, |
| 1297 |
connection=connection, |
| 1298 |
fields=fields, |
| 1299 |
include_fields=include_fields, |
| 1300 |
q=q, |
| 1301 |
search_engine=search_engine, |
| 1302 |
primary_order=primary_order, |
| 1303 |
request_options=request_options, |
| 1304 |
) |
| 1305 |
|
| 1306 |
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 1307 |
if _response.status_code == 400: |
| 1308 |
raise BadRequestError( |
| 1309 |
headers=dict(_response.headers), |
| 1310 |
body=typing.cast( |
| 1311 |
typing.Any, |
| 1312 |
parse_obj_as( |
| 1313 |
type_=typing.Any, |
| 1314 |
object_=_response.json(), |
| 1315 |
), |
| 1316 |
), |
| 1317 |
) |
| 1318 |
if _response.status_code == 401: |
| 1319 |
raise UnauthorizedError( |
| 1320 |
headers=dict(_response.headers), |
| 1321 |
body=typing.cast( |
| 1322 |
typing.Any, |
| 1323 |
parse_obj_as( |
| 1324 |
type_=typing.Any, |
| 1325 |
object_=_response.json(), |
| 1326 |
), |
| 1327 |
), |
| 1328 |
) |
| 1329 |
if _response.status_code == 403: |
| 1330 |
raise ForbiddenError( |
| 1331 |
headers=dict(_response.headers), |
| 1332 |
body=typing.cast( |
| 1333 |
typing.Any, |
| 1334 |
parse_obj_as( |
| 1335 |
type_=typing.Any, |
| 1336 |
object_=_response.json(), |
| 1337 |
), |
| 1338 |
), |
| 1339 |
) |
| 1340 |
if _response.status_code == 429: |
| 1341 |
raise TooManyRequestsError( |
| 1342 |
headers=dict(_response.headers), |
| 1343 |
body=typing.cast( |
| 1344 |
typing.Any, |
| 1345 |
parse_obj_as( |
| 1346 |
type_=typing.Any, |
| 1347 |
object_=_response.json(), |
| 1348 |
), |
| 1349 |
), |
| 1350 |
) |
| 1351 |
if _response.status_code == 503: |
| 1352 |
raise ServiceUnavailableError( |
| 1353 |
headers=dict(_response.headers), |
| 1354 |
body=typing.cast( |
| 1355 |
typing.Any, |
| 1356 |
parse_obj_as( |
| 1357 |
type_=typing.Any, |
| 1358 |
object_=_response.json(), |
| 1359 |
), |
| 1360 |
), |
| 1361 |
) |
| 1362 |
_response_json = _response.json() |
| 1363 |
except JSONDecodeError: |
| 1364 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1365 |
except ValidationError as e: |
| 1366 |
raise ParsingError( |
| 1367 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1368 |
) |
| 1369 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1370 |
|
| 1371 |
async def create( |
| 1372 |
self, |
| 1373 |
*, |
| 1374 |
connection: str, |
| 1375 |
email: typing.Optional[str] = OMIT, |
| 1376 |
phone_number: typing.Optional[str] = OMIT, |
| 1377 |
user_metadata: typing.Optional[UserMetadata] = OMIT, |
| 1378 |
blocked: typing.Optional[bool] = OMIT, |
| 1379 |
email_verified: typing.Optional[bool] = OMIT, |
| 1380 |
phone_verified: typing.Optional[bool] = OMIT, |
| 1381 |
app_metadata: typing.Optional[AppMetadata] = OMIT, |
| 1382 |
given_name: typing.Optional[str] = OMIT, |
| 1383 |
family_name: typing.Optional[str] = OMIT, |
| 1384 |
name: typing.Optional[str] = OMIT, |
| 1385 |
nickname: typing.Optional[str] = OMIT, |
| 1386 |
picture: typing.Optional[str] = OMIT, |
| 1387 |
user_id: typing.Optional[str] = OMIT, |
| 1388 |
password: typing.Optional[str] = OMIT, |
| 1389 |
verify_email: typing.Optional[bool] = OMIT, |
| 1390 |
username: typing.Optional[str] = OMIT, |
| 1391 |
request_options: typing.Optional[RequestOptions] = None, |
| 1392 |
) -> AsyncHttpResponse[CreateUserResponseContent]: |
| 1393 |
""" |
| 1394 |
Create a new user for a given [database](https://auth0.com/docs/connections/database) or [passwordless](https://auth0.com/docs/connections/passwordless) connection. |
| 1395 |
|
| 1396 |
Note: `connection` is required but other parameters such as `email` and `password` are dependent upon the type of connection. |
| 1397 |
|
| 1398 |
Parameters |
| 1399 |
---------- |
| 1400 |
connection : str |
| 1401 |
Name of the connection this user should be created in. |
| 1402 |
|
| 1403 |
email : typing.Optional[str] |
| 1404 |
The user's email. |
| 1405 |
|
| 1406 |
phone_number : typing.Optional[str] |
| 1407 |
The user's phone number (following the E.164 recommendation). |
| 1408 |
|
| 1409 |
user_metadata : typing.Optional[UserMetadata] |
| 1410 |
|
| 1411 |
blocked : typing.Optional[bool] |
| 1412 |
Whether this user was blocked by an administrator (true) or not (false). |
| 1413 |
|
| 1414 |
email_verified : typing.Optional[bool] |
| 1415 |
Whether this email address is verified (true) or unverified (false). User will receive a verification email after creation if `email_verified` is false or not specified |
| 1416 |
|
| 1417 |
phone_verified : typing.Optional[bool] |
| 1418 |
Whether this phone number has been verified (true) or not (false). |
| 1419 |
|
| 1420 |
app_metadata : typing.Optional[AppMetadata] |
| 1421 |
|
| 1422 |
given_name : typing.Optional[str] |
| 1423 |
The user's given name(s). |
| 1424 |
|
| 1425 |
family_name : typing.Optional[str] |
| 1426 |
The user's family name(s). |
| 1427 |
|
| 1428 |
name : typing.Optional[str] |
| 1429 |
The user's full name. |
| 1430 |
|
| 1431 |
nickname : typing.Optional[str] |
| 1432 |
The user's nickname. |
| 1433 |
|
| 1434 |
picture : typing.Optional[str] |
| 1435 |
A URI pointing to the user's picture. |
| 1436 |
|
| 1437 |
user_id : typing.Optional[str] |
| 1438 |
The external user's id provided by the identity provider. |
| 1439 |
|
| 1440 |
password : typing.Optional[str] |
| 1441 |
Initial password for this user. Only valid for auth0 connection strategy. |
| 1442 |
|
| 1443 |
verify_email : typing.Optional[bool] |
| 1444 |
Whether the user will receive a verification email after creation (true) or no email (false). Overrides behavior of `email_verified` parameter. |
| 1445 |
|
| 1446 |
username : typing.Optional[str] |
| 1447 |
The user's username. Only valid if the connection requires a username. |
| 1448 |
|
| 1449 |
request_options : typing.Optional[RequestOptions] |
| 1450 |
Request-specific configuration. |
| 1451 |
|
| 1452 |
Returns |
| 1453 |
------- |
| 1454 |
AsyncHttpResponse[CreateUserResponseContent] |
| 1455 |
User successfully created. |
| 1456 |
""" |
| 1457 |
_response = await self._client_wrapper.httpx_client.request( |
| 1458 |
"users", |
| 1459 |
method="POST", |
| 1460 |
json={ |
| 1461 |
"email": email, |
| 1462 |
"phone_number": phone_number, |
| 1463 |
"user_metadata": user_metadata, |
| 1464 |
"blocked": blocked, |
| 1465 |
"email_verified": email_verified, |
| 1466 |
"phone_verified": phone_verified, |
| 1467 |
"app_metadata": app_metadata, |
| 1468 |
"given_name": given_name, |
| 1469 |
"family_name": family_name, |
| 1470 |
"name": name, |
| 1471 |
"nickname": nickname, |
| 1472 |
"picture": picture, |
| 1473 |
"user_id": user_id, |
| 1474 |
"connection": connection, |
| 1475 |
"password": password, |
| 1476 |
"verify_email": verify_email, |
| 1477 |
"username": username, |
| 1478 |
}, |
| 1479 |
headers={ |
| 1480 |
"content-type": "application/json", |
| 1481 |
}, |
| 1482 |
request_options=request_options, |
| 1483 |
omit=OMIT, |
| 1484 |
) |
| 1485 |
try: |
| 1486 |
if 200 <= _response.status_code < 300: |
| 1487 |
_data = typing.cast( |
| 1488 |
CreateUserResponseContent, |
| 1489 |
parse_obj_as( |
| 1490 |
type_=CreateUserResponseContent, |
| 1491 |
object_=_response.json(), |
| 1492 |
), |
| 1493 |
) |
| 1494 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1495 |
if _response.status_code == 400: |
| 1496 |
raise BadRequestError( |
| 1497 |
headers=dict(_response.headers), |
| 1498 |
body=typing.cast( |
| 1499 |
typing.Any, |
| 1500 |
parse_obj_as( |
| 1501 |
type_=typing.Any, |
| 1502 |
object_=_response.json(), |
| 1503 |
), |
| 1504 |
), |
| 1505 |
) |
| 1506 |
if _response.status_code == 401: |
| 1507 |
raise UnauthorizedError( |
| 1508 |
headers=dict(_response.headers), |
| 1509 |
body=typing.cast( |
| 1510 |
typing.Any, |
| 1511 |
parse_obj_as( |
| 1512 |
type_=typing.Any, |
| 1513 |
object_=_response.json(), |
| 1514 |
), |
| 1515 |
), |
| 1516 |
) |
| 1517 |
if _response.status_code == 403: |
| 1518 |
raise ForbiddenError( |
| 1519 |
headers=dict(_response.headers), |
| 1520 |
body=typing.cast( |
| 1521 |
typing.Any, |
| 1522 |
parse_obj_as( |
| 1523 |
type_=typing.Any, |
| 1524 |
object_=_response.json(), |
| 1525 |
), |
| 1526 |
), |
| 1527 |
) |
| 1528 |
if _response.status_code == 409: |
| 1529 |
raise ConflictError( |
| 1530 |
headers=dict(_response.headers), |
| 1531 |
body=typing.cast( |
| 1532 |
typing.Any, |
| 1533 |
parse_obj_as( |
| 1534 |
type_=typing.Any, |
| 1535 |
object_=_response.json(), |
| 1536 |
), |
| 1537 |
), |
| 1538 |
) |
| 1539 |
if _response.status_code == 429: |
| 1540 |
raise TooManyRequestsError( |
| 1541 |
headers=dict(_response.headers), |
| 1542 |
body=typing.cast( |
| 1543 |
typing.Any, |
| 1544 |
parse_obj_as( |
| 1545 |
type_=typing.Any, |
| 1546 |
object_=_response.json(), |
| 1547 |
), |
| 1548 |
), |
| 1549 |
) |
| 1550 |
_response_json = _response.json() |
| 1551 |
except JSONDecodeError: |
| 1552 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1553 |
except ValidationError as e: |
| 1554 |
raise ParsingError( |
| 1555 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1556 |
) |
| 1557 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1558 |
|
| 1559 |
async def list_users_by_email( |
| 1560 |
self, |
| 1561 |
*, |
| 1562 |
email: str, |
| 1563 |
fields: typing.Optional[str] = None, |
| 1564 |
include_fields: typing.Optional[bool] = None, |
| 1565 |
request_options: typing.Optional[RequestOptions] = None, |
| 1566 |
) -> AsyncHttpResponse[typing.List[UserResponseSchema]]: |
| 1567 |
""" |
| 1568 |
Find users by email. If Auth0 is the identity provider (idP), the email address associated with a user is saved in lower case, regardless of how you initially provided it. |
| 1569 |
|
| 1570 |
For example, if you register a user as [email protected], Auth0 saves the user's email as [email protected]. |
| 1571 |
|
| 1572 |
Therefore, when using this endpoint, make sure that you are searching for users via email addresses using the correct case. |
| 1573 |
|
| 1574 |
Parameters |
| 1575 |
---------- |
| 1576 |
email : str |
| 1577 |
Email address to search for (case-sensitive). |
| 1578 |
|
| 1579 |
fields : typing.Optional[str] |
| 1580 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 1581 |
|
| 1582 |
include_fields : typing.Optional[bool] |
| 1583 |
Whether specified fields are to be included (true) or excluded (false). Defaults to true. |
| 1584 |
|
| 1585 |
request_options : typing.Optional[RequestOptions] |
| 1586 |
Request-specific configuration. |
| 1587 |
|
| 1588 |
Returns |
| 1589 |
------- |
| 1590 |
AsyncHttpResponse[typing.List[UserResponseSchema]] |
| 1591 |
Users successfully searched. |
| 1592 |
""" |
| 1593 |
_response = await self._client_wrapper.httpx_client.request( |
| 1594 |
"users-by-email", |
| 1595 |
method="GET", |
| 1596 |
params={ |
| 1597 |
"fields": fields, |
| 1598 |
"include_fields": include_fields, |
| 1599 |
"email": email, |
| 1600 |
}, |
| 1601 |
request_options=request_options, |
| 1602 |
) |
| 1603 |
try: |
| 1604 |
if 200 <= _response.status_code < 300: |
| 1605 |
_data = typing.cast( |
| 1606 |
typing.List[UserResponseSchema], |
| 1607 |
parse_obj_as( |
| 1608 |
type_=typing.List[UserResponseSchema], |
| 1609 |
object_=_response.json(), |
| 1610 |
), |
| 1611 |
) |
| 1612 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1613 |
if _response.status_code == 400: |
| 1614 |
raise BadRequestError( |
| 1615 |
headers=dict(_response.headers), |
| 1616 |
body=typing.cast( |
| 1617 |
typing.Any, |
| 1618 |
parse_obj_as( |
| 1619 |
type_=typing.Any, |
| 1620 |
object_=_response.json(), |
| 1621 |
), |
| 1622 |
), |
| 1623 |
) |
| 1624 |
if _response.status_code == 401: |
| 1625 |
raise UnauthorizedError( |
| 1626 |
headers=dict(_response.headers), |
| 1627 |
body=typing.cast( |
| 1628 |
typing.Any, |
| 1629 |
parse_obj_as( |
| 1630 |
type_=typing.Any, |
| 1631 |
object_=_response.json(), |
| 1632 |
), |
| 1633 |
), |
| 1634 |
) |
| 1635 |
if _response.status_code == 403: |
| 1636 |
raise ForbiddenError( |
| 1637 |
headers=dict(_response.headers), |
| 1638 |
body=typing.cast( |
| 1639 |
typing.Any, |
| 1640 |
parse_obj_as( |
| 1641 |
type_=typing.Any, |
| 1642 |
object_=_response.json(), |
| 1643 |
), |
| 1644 |
), |
| 1645 |
) |
| 1646 |
if _response.status_code == 429: |
| 1647 |
raise TooManyRequestsError( |
| 1648 |
headers=dict(_response.headers), |
| 1649 |
body=typing.cast( |
| 1650 |
typing.Any, |
| 1651 |
parse_obj_as( |
| 1652 |
type_=typing.Any, |
| 1653 |
object_=_response.json(), |
| 1654 |
), |
| 1655 |
), |
| 1656 |
) |
| 1657 |
_response_json = _response.json() |
| 1658 |
except JSONDecodeError: |
| 1659 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1660 |
except ValidationError as e: |
| 1661 |
raise ParsingError( |
| 1662 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1663 |
) |
| 1664 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1665 |
|
| 1666 |
async def get( |
| 1667 |
self, |
| 1668 |
id: str, |
| 1669 |
*, |
| 1670 |
fields: typing.Optional[str] = None, |
| 1671 |
include_fields: typing.Optional[bool] = None, |
| 1672 |
request_options: typing.Optional[RequestOptions] = None, |
| 1673 |
) -> AsyncHttpResponse[GetUserResponseContent]: |
| 1674 |
""" |
| 1675 |
Retrieve user details. A list of fields to include or exclude may also be specified. For more information, see [Retrieve Users with the Get Users Endpoint](https://auth0.com/docs/manage-users/user-search/retrieve-users-with-get-users-endpoint). |
| 1676 |
|
| 1677 |
Parameters |
| 1678 |
---------- |
| 1679 |
id : str |
| 1680 |
ID of the user to retrieve. |
| 1681 |
|
| 1682 |
fields : typing.Optional[str] |
| 1683 |
Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields. |
| 1684 |
|
| 1685 |
include_fields : typing.Optional[bool] |
| 1686 |
Whether specified fields are to be included (true) or excluded (false). |
| 1687 |
|
| 1688 |
request_options : typing.Optional[RequestOptions] |
| 1689 |
Request-specific configuration. |
| 1690 |
|
| 1691 |
Returns |
| 1692 |
------- |
| 1693 |
AsyncHttpResponse[GetUserResponseContent] |
| 1694 |
User successfully retrieved. |
| 1695 |
""" |
| 1696 |
_response = await self._client_wrapper.httpx_client.request( |
| 1697 |
f"users/{encode_path_param(id)}", |
| 1698 |
method="GET", |
| 1699 |
params={ |
| 1700 |
"fields": fields, |
| 1701 |
"include_fields": include_fields, |
| 1702 |
}, |
| 1703 |
request_options=request_options, |
| 1704 |
) |
| 1705 |
try: |
| 1706 |
if 200 <= _response.status_code < 300: |
| 1707 |
_data = typing.cast( |
| 1708 |
GetUserResponseContent, |
| 1709 |
parse_obj_as( |
| 1710 |
type_=GetUserResponseContent, |
| 1711 |
object_=_response.json(), |
| 1712 |
), |
| 1713 |
) |
| 1714 |
return AsyncHttpResponse(response=_response, data=_data) |
| 1715 |
if _response.status_code == 400: |
| 1716 |
raise BadRequestError( |
| 1717 |
headers=dict(_response.headers), |
| 1718 |
body=typing.cast( |
| 1719 |
typing.Any, |
| 1720 |
parse_obj_as( |
| 1721 |
type_=typing.Any, |
| 1722 |
object_=_response.json(), |
| 1723 |
), |
| 1724 |
), |
| 1725 |
) |
| 1726 |
if _response.status_code == 401: |
| 1727 |
raise UnauthorizedError( |
| 1728 |
headers=dict(_response.headers), |
| 1729 |
body=typing.cast( |
| 1730 |
typing.Any, |
| 1731 |
parse_obj_as( |
| 1732 |
type_=typing.Any, |
| 1733 |
object_=_response.json(), |
| 1734 |
), |
| 1735 |
), |
| 1736 |
) |
| 1737 |
if _response.status_code == 403: |
| 1738 |
raise ForbiddenError( |
| 1739 |
headers=dict(_response.headers), |
| 1740 |
body=typing.cast( |
| 1741 |
typing.Any, |
| 1742 |
parse_obj_as( |
| 1743 |
type_=typing.Any, |
| 1744 |
object_=_response.json(), |
| 1745 |
), |
| 1746 |
), |
| 1747 |
) |
| 1748 |
if _response.status_code == 404: |
| 1749 |
raise NotFoundError( |
| 1750 |
headers=dict(_response.headers), |
| 1751 |
body=typing.cast( |
| 1752 |
typing.Any, |
| 1753 |
parse_obj_as( |
| 1754 |
type_=typing.Any, |
| 1755 |
object_=_response.json(), |
| 1756 |
), |
| 1757 |
), |
| 1758 |
) |
| 1759 |
if _response.status_code == 429: |
| 1760 |
raise TooManyRequestsError( |
| 1761 |
headers=dict(_response.headers), |
| 1762 |
body=typing.cast( |
| 1763 |
typing.Any, |
| 1764 |
parse_obj_as( |
| 1765 |
type_=typing.Any, |
| 1766 |
object_=_response.json(), |
| 1767 |
), |
| 1768 |
), |
| 1769 |
) |
| 1770 |
_response_json = _response.json() |
| 1771 |
except JSONDecodeError: |
| 1772 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1773 |
except ValidationError as e: |
| 1774 |
raise ParsingError( |
| 1775 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1776 |
) |
| 1777 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1778 |
|
| 1779 |
async def delete( |
| 1780 |
self, id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 1781 |
) -> AsyncHttpResponse[None]: |
| 1782 |
""" |
| 1783 |
Delete a user by user ID. This action cannot be undone. For Auth0 Dashboard instructions, see [Delete Users](https://auth0.com/docs/manage-users/user-accounts/delete-users). |
| 1784 |
|
| 1785 |
Parameters |
| 1786 |
---------- |
| 1787 |
id : str |
| 1788 |
ID of the user to delete. |
| 1789 |
|
| 1790 |
request_options : typing.Optional[RequestOptions] |
| 1791 |
Request-specific configuration. |
| 1792 |
|
| 1793 |
Returns |
| 1794 |
------- |
| 1795 |
AsyncHttpResponse[None] |
| 1796 |
""" |
| 1797 |
_response = await self._client_wrapper.httpx_client.request( |
| 1798 |
f"users/{encode_path_param(id)}", |
| 1799 |
method="DELETE", |
| 1800 |
request_options=request_options, |
| 1801 |
) |
| 1802 |
try: |
| 1803 |
if 200 <= _response.status_code < 300: |
| 1804 |
return AsyncHttpResponse(response=_response, data=None) |
| 1805 |
if _response.status_code == 400: |
| 1806 |
raise BadRequestError( |
| 1807 |
headers=dict(_response.headers), |
| 1808 |
body=typing.cast( |
| 1809 |
typing.Any, |
| 1810 |
parse_obj_as( |
| 1811 |
type_=typing.Any, |
| 1812 |
object_=_response.json(), |
| 1813 |
), |
| 1814 |
), |
| 1815 |
) |
| 1816 |
if _response.status_code == 401: |
| 1817 |
raise UnauthorizedError( |
| 1818 |
headers=dict(_response.headers), |
| 1819 |
body=typing.cast( |
| 1820 |
typing.Any, |
| 1821 |
parse_obj_as( |
| 1822 |
type_=typing.Any, |
| 1823 |
object_=_response.json(), |
| 1824 |
), |
| 1825 |
), |
| 1826 |
) |
| 1827 |
if _response.status_code == 403: |
| 1828 |
raise ForbiddenError( |
| 1829 |
headers=dict(_response.headers), |
| 1830 |
body=typing.cast( |
| 1831 |
typing.Any, |
| 1832 |
parse_obj_as( |
| 1833 |
type_=typing.Any, |
| 1834 |
object_=_response.json(), |
| 1835 |
), |
| 1836 |
), |
| 1837 |
) |
| 1838 |
if _response.status_code == 429: |
| 1839 |
raise TooManyRequestsError( |
| 1840 |
headers=dict(_response.headers), |
| 1841 |
body=typing.cast( |
| 1842 |
typing.Any, |
| 1843 |
parse_obj_as( |
| 1844 |
type_=typing.Any, |
| 1845 |
object_=_response.json(), |
| 1846 |
), |
| 1847 |
), |
| 1848 |
) |
| 1849 |
_response_json = _response.json() |
| 1850 |
except JSONDecodeError: |
| 1851 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 1852 |
except ValidationError as e: |
| 1853 |
raise ParsingError( |
| 1854 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 1855 |
) |
| 1856 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 1857 |
|
| 1858 |
async def update( |
| 1859 |
self, |
| 1860 |
id: str, |
| 1861 |
*, |
| 1862 |
blocked: typing.Optional[bool] = OMIT, |
| 1863 |
email_verified: typing.Optional[bool] = OMIT, |
| 1864 |
email: typing.Optional[str] = OMIT, |
| 1865 |
phone_number: typing.Optional[str] = OMIT, |
| 1866 |
phone_verified: typing.Optional[bool] = OMIT, |
| 1867 |
user_metadata: typing.Optional[UserMetadata] = OMIT, |
| 1868 |
app_metadata: typing.Optional[AppMetadata] = OMIT, |
| 1869 |
given_name: typing.Optional[str] = OMIT, |
| 1870 |
family_name: typing.Optional[str] = OMIT, |
| 1871 |
name: typing.Optional[str] = OMIT, |
| 1872 |
nickname: typing.Optional[str] = OMIT, |
| 1873 |
picture: typing.Optional[str] = OMIT, |
| 1874 |
verify_email: typing.Optional[bool] = OMIT, |
| 1875 |
verify_phone_number: typing.Optional[bool] = OMIT, |
| 1876 |
password: typing.Optional[str] = OMIT, |
| 1877 |
connection: typing.Optional[str] = OMIT, |
| 1878 |
client_id: typing.Optional[str] = OMIT, |
| 1879 |
username: typing.Optional[str] = OMIT, |
| 1880 |
request_options: typing.Optional[RequestOptions] = None, |
| 1881 |
) -> AsyncHttpResponse[UpdateUserResponseContent]: |
| 1882 |
""" |
| 1883 |
Update a user. |
| 1884 |
|
| 1885 |
These are the attributes that can be updated at the root level: |
| 1886 |
|
| 1887 |
- app_metadata |
| 1888 |
- blocked |
| 1889 |
- email |
| 1890 |
- email_verified |
| 1891 |
- family_name |
| 1892 |
- given_name |
| 1893 |
- name |
| 1894 |
- nickname |
| 1895 |
- password |
| 1896 |
- phone_number |
| 1897 |
- phone_verified |
| 1898 |
- picture |
| 1899 |
- username |
| 1900 |
- user_metadata |
| 1901 |
- verify_email |
| 1902 |
|
| 1903 |
Some considerations: |
| 1904 |
|
| 1905 |
- The properties of the new object will replace the old ones. |
| 1906 |
- The metadata fields are an exception to this rule (`user_metadata` and `app_metadata`). These properties are merged instead of being replaced but be careful, the merge only occurs on the first level. |
| 1907 |
- If you are updating `email`, `email_verified`, `phone_number`, `phone_verified`, `username` or `password` of a secondary identity, you need to specify the `connection` property too. |
| 1908 |
- If you are updating `email` or `phone_number` you can specify, optionally, the `client_id` property. |
| 1909 |
- Updating `email_verified` is not supported for enterprise and passwordless sms connections. |
| 1910 |
- Updating the `blocked` to `false` does not affect the user's blocked state from an excessive amount of incorrectly provided credentials. Use the "Unblock a user" endpoint from the "User Blocks" API to change the user's state. |
| 1911 |
- Supported attributes can be unset by supplying `null` as the value. |
| 1912 |
|
| 1913 |
**Updating a field (non-metadata property)** |
| 1914 |
|
| 1915 |
To mark the email address of a user as verified, the body to send should be: |
| 1916 |
|
| 1917 |
```json |
| 1918 |
{ "email_verified": true } |
| 1919 |
``` |
| 1920 |
|
| 1921 |
**Updating a user metadata root property** |
| 1922 |
|
| 1923 |
Let's assume that our test user has the following `user_metadata`: |
| 1924 |
|
| 1925 |
```json |
| 1926 |
{ "user_metadata" : { "profileCode": 1479 } } |
| 1927 |
``` |
| 1928 |
|
| 1929 |
To add the field `addresses` the body to send should be: |
| 1930 |
|
| 1931 |
```json |
| 1932 |
{ "user_metadata" : { "addresses": {"work_address": "100 Industrial Way"} }} |
| 1933 |
``` |
| 1934 |
|
| 1935 |
The modified object ends up with the following `user_metadata` property: |
| 1936 |
|
| 1937 |
```json |
| 1938 |
{ |
| 1939 |
"user_metadata": { |
| 1940 |
"profileCode": 1479, |
| 1941 |
"addresses": { "work_address": "100 Industrial Way" } |
| 1942 |
} |
| 1943 |
} |
| 1944 |
``` |
| 1945 |
|
| 1946 |
**Updating an inner user metadata property** |
| 1947 |
|
| 1948 |
If there's existing user metadata to which we want to add `"home_address": "742 Evergreen Terrace"` (using the `addresses` property) we should send the whole `addresses` object. Since this is a first-level object, the object will be merged in, but its own properties will not be. The body to send should be: |
| 1949 |
|
| 1950 |
```json |
| 1951 |
{ |
| 1952 |
"user_metadata": { |
| 1953 |
"addresses": { |
| 1954 |
"work_address": "100 Industrial Way", |
| 1955 |
"home_address": "742 Evergreen Terrace" |
| 1956 |
} |
| 1957 |
} |
| 1958 |
} |
| 1959 |
``` |
| 1960 |
|
| 1961 |
The modified object ends up with the following `user_metadata` property: |
| 1962 |
|
| 1963 |
```json |
| 1964 |
{ |
| 1965 |
"user_metadata": { |
| 1966 |
"profileCode": 1479, |
| 1967 |
"addresses": { |
| 1968 |
"work_address": "100 Industrial Way", |
| 1969 |
"home_address": "742 Evergreen Terrace" |
| 1970 |
} |
| 1971 |
} |
| 1972 |
} |
| 1973 |
``` |
| 1974 |
|
| 1975 |
Parameters |
| 1976 |
---------- |
| 1977 |
id : str |
| 1978 |
ID of the user to update. |
| 1979 |
|
| 1980 |
blocked : typing.Optional[bool] |
| 1981 |
Whether this user was blocked by an administrator (true) or not (false). |
| 1982 |
|
| 1983 |
email_verified : typing.Optional[bool] |
| 1984 |
Whether this email address is verified (true) or unverified (false). If set to false the user will not receive a verification email unless `verify_email` is set to true. |
| 1985 |
|
| 1986 |
email : typing.Optional[str] |
| 1987 |
Email address of this user. |
| 1988 |
|
| 1989 |
phone_number : typing.Optional[str] |
| 1990 |
The user's phone number (following the E.164 recommendation). |
| 1991 |
|
| 1992 |
phone_verified : typing.Optional[bool] |
| 1993 |
Whether this phone number has been verified (true) or not (false). |
| 1994 |
|
| 1995 |
user_metadata : typing.Optional[UserMetadata] |
| 1996 |
User metadata to which this user has read/write access. |
| 1997 |
|
| 1998 |
app_metadata : typing.Optional[AppMetadata] |
| 1999 |
User metadata to which this user has read-only access. |
| 2000 |
|
| 2001 |
given_name : typing.Optional[str] |
| 2002 |
Given name/first name/forename of this user. |
| 2003 |
|
| 2004 |
family_name : typing.Optional[str] |
| 2005 |
Family name/last name/surname of this user. |
| 2006 |
|
| 2007 |
name : typing.Optional[str] |
| 2008 |
Name of this user. |
| 2009 |
|
| 2010 |
nickname : typing.Optional[str] |
| 2011 |
Preferred nickname or alias of this user. |
| 2012 |
|
| 2013 |
picture : typing.Optional[str] |
| 2014 |
URL to picture, photo, or avatar of this user. |
| 2015 |
|
| 2016 |
verify_email : typing.Optional[bool] |
| 2017 |
Whether this user will receive a verification email after creation (true) or no email (false). Overrides behavior of `email_verified` parameter. |
| 2018 |
|
| 2019 |
verify_phone_number : typing.Optional[bool] |
| 2020 |
Whether this user will receive a text after changing the phone number (true) or no text (false). Only valid when changing phone number for SMS connections. |
| 2021 |
|
| 2022 |
password : typing.Optional[str] |
| 2023 |
New password for this user. Only valid for database connections. |
| 2024 |
|
| 2025 |
connection : typing.Optional[str] |
| 2026 |
Name of the connection to target for this user update. |
| 2027 |
|
| 2028 |
client_id : typing.Optional[str] |
| 2029 |
Auth0 client ID. Only valid when updating email address. |
| 2030 |
|
| 2031 |
username : typing.Optional[str] |
| 2032 |
The user's username. Only valid if the connection requires a username. |
| 2033 |
|
| 2034 |
request_options : typing.Optional[RequestOptions] |
| 2035 |
Request-specific configuration. |
| 2036 |
|
| 2037 |
Returns |
| 2038 |
------- |
| 2039 |
AsyncHttpResponse[UpdateUserResponseContent] |
| 2040 |
User successfully updated. |
| 2041 |
""" |
| 2042 |
_response = await self._client_wrapper.httpx_client.request( |
| 2043 |
f"users/{encode_path_param(id)}", |
| 2044 |
method="PATCH", |
| 2045 |
json={ |
| 2046 |
"blocked": blocked, |
| 2047 |
"email_verified": email_verified, |
| 2048 |
"email": email, |
| 2049 |
"phone_number": phone_number, |
| 2050 |
"phone_verified": phone_verified, |
| 2051 |
"user_metadata": user_metadata, |
| 2052 |
"app_metadata": app_metadata, |
| 2053 |
"given_name": given_name, |
| 2054 |
"family_name": family_name, |
| 2055 |
"name": name, |
| 2056 |
"nickname": nickname, |
| 2057 |
"picture": picture, |
| 2058 |
"verify_email": verify_email, |
| 2059 |
"verify_phone_number": verify_phone_number, |
| 2060 |
"password": password, |
| 2061 |
"connection": connection, |
| 2062 |
"client_id": client_id, |
| 2063 |
"username": username, |
| 2064 |
}, |
| 2065 |
headers={ |
| 2066 |
"content-type": "application/json", |
| 2067 |
}, |
| 2068 |
request_options=request_options, |
| 2069 |
omit=OMIT, |
| 2070 |
) |
| 2071 |
try: |
| 2072 |
if 200 <= _response.status_code < 300: |
| 2073 |
_data = typing.cast( |
| 2074 |
UpdateUserResponseContent, |
| 2075 |
parse_obj_as( |
| 2076 |
type_=UpdateUserResponseContent, |
| 2077 |
object_=_response.json(), |
| 2078 |
), |
| 2079 |
) |
| 2080 |
return AsyncHttpResponse(response=_response, data=_data) |
| 2081 |
if _response.status_code == 400: |
| 2082 |
raise BadRequestError( |
| 2083 |
headers=dict(_response.headers), |
| 2084 |
body=typing.cast( |
| 2085 |
typing.Any, |
| 2086 |
parse_obj_as( |
| 2087 |
type_=typing.Any, |
| 2088 |
object_=_response.json(), |
| 2089 |
), |
| 2090 |
), |
| 2091 |
) |
| 2092 |
if _response.status_code == 401: |
| 2093 |
raise UnauthorizedError( |
| 2094 |
headers=dict(_response.headers), |
| 2095 |
body=typing.cast( |
| 2096 |
typing.Any, |
| 2097 |
parse_obj_as( |
| 2098 |
type_=typing.Any, |
| 2099 |
object_=_response.json(), |
| 2100 |
), |
| 2101 |
), |
| 2102 |
) |
| 2103 |
if _response.status_code == 403: |
| 2104 |
raise ForbiddenError( |
| 2105 |
headers=dict(_response.headers), |
| 2106 |
body=typing.cast( |
| 2107 |
typing.Any, |
| 2108 |
parse_obj_as( |
| 2109 |
type_=typing.Any, |
| 2110 |
object_=_response.json(), |
| 2111 |
), |
| 2112 |
), |
| 2113 |
) |
| 2114 |
if _response.status_code == 404: |
| 2115 |
raise NotFoundError( |
| 2116 |
headers=dict(_response.headers), |
| 2117 |
body=typing.cast( |
| 2118 |
typing.Any, |
| 2119 |
parse_obj_as( |
| 2120 |
type_=typing.Any, |
| 2121 |
object_=_response.json(), |
| 2122 |
), |
| 2123 |
), |
| 2124 |
) |
| 2125 |
if _response.status_code == 429: |
| 2126 |
raise TooManyRequestsError( |
| 2127 |
headers=dict(_response.headers), |
| 2128 |
body=typing.cast( |
| 2129 |
typing.Any, |
| 2130 |
parse_obj_as( |
| 2131 |
type_=typing.Any, |
| 2132 |
object_=_response.json(), |
| 2133 |
), |
| 2134 |
), |
| 2135 |
) |
| 2136 |
_response_json = _response.json() |
| 2137 |
except JSONDecodeError: |
| 2138 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 2139 |
except ValidationError as e: |
| 2140 |
raise ParsingError( |
| 2141 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 2142 |
) |
| 2143 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 2144 |
|
| 2145 |
async def regenerate_recovery_code( |
| 2146 |
self, id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 2147 |
) -> AsyncHttpResponse[RegenerateUsersRecoveryCodeResponseContent]: |
| 2148 |
""" |
| 2149 |
Remove an existing multi-factor authentication (MFA) [recovery code](https://auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa) and generate a new one. If a user cannot access the original device or account used for MFA enrollment, they can use a recovery code to authenticate. |
| 2150 |
|
| 2151 |
Parameters |
| 2152 |
---------- |
| 2153 |
id : str |
| 2154 |
ID of the user to regenerate a multi-factor authentication recovery code for. |
| 2155 |
|
| 2156 |
request_options : typing.Optional[RequestOptions] |
| 2157 |
Request-specific configuration. |
| 2158 |
|
| 2159 |
Returns |
| 2160 |
------- |
| 2161 |
AsyncHttpResponse[RegenerateUsersRecoveryCodeResponseContent] |
| 2162 |
New recovery code successfully generated. |
| 2163 |
""" |
| 2164 |
_response = await self._client_wrapper.httpx_client.request( |
| 2165 |
f"users/{encode_path_param(id)}/recovery-code-regeneration", |
| 2166 |
method="POST", |
| 2167 |
request_options=request_options, |
| 2168 |
) |
| 2169 |
try: |
| 2170 |
if 200 <= _response.status_code < 300: |
| 2171 |
_data = typing.cast( |
| 2172 |
RegenerateUsersRecoveryCodeResponseContent, |
| 2173 |
parse_obj_as( |
| 2174 |
type_=RegenerateUsersRecoveryCodeResponseContent, |
| 2175 |
object_=_response.json(), |
| 2176 |
), |
| 2177 |
) |
| 2178 |
return AsyncHttpResponse(response=_response, data=_data) |
| 2179 |
if _response.status_code == 400: |
| 2180 |
raise BadRequestError( |
| 2181 |
headers=dict(_response.headers), |
| 2182 |
body=typing.cast( |
| 2183 |
typing.Any, |
| 2184 |
parse_obj_as( |
| 2185 |
type_=typing.Any, |
| 2186 |
object_=_response.json(), |
| 2187 |
), |
| 2188 |
), |
| 2189 |
) |
| 2190 |
if _response.status_code == 401: |
| 2191 |
raise UnauthorizedError( |
| 2192 |
headers=dict(_response.headers), |
| 2193 |
body=typing.cast( |
| 2194 |
typing.Any, |
| 2195 |
parse_obj_as( |
| 2196 |
type_=typing.Any, |
| 2197 |
object_=_response.json(), |
| 2198 |
), |
| 2199 |
), |
| 2200 |
) |
| 2201 |
if _response.status_code == 403: |
| 2202 |
raise ForbiddenError( |
| 2203 |
headers=dict(_response.headers), |
| 2204 |
body=typing.cast( |
| 2205 |
typing.Any, |
| 2206 |
parse_obj_as( |
| 2207 |
type_=typing.Any, |
| 2208 |
object_=_response.json(), |
| 2209 |
), |
| 2210 |
), |
| 2211 |
) |
| 2212 |
if _response.status_code == 404: |
| 2213 |
raise NotFoundError( |
| 2214 |
headers=dict(_response.headers), |
| 2215 |
body=typing.cast( |
| 2216 |
typing.Any, |
| 2217 |
parse_obj_as( |
| 2218 |
type_=typing.Any, |
| 2219 |
object_=_response.json(), |
| 2220 |
), |
| 2221 |
), |
| 2222 |
) |
| 2223 |
_response_json = _response.json() |
| 2224 |
except JSONDecodeError: |
| 2225 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 2226 |
except ValidationError as e: |
| 2227 |
raise ParsingError( |
| 2228 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 2229 |
) |
| 2230 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 2231 |
|
| 2232 |
async def revoke_access( |
| 2233 |
self, |
| 2234 |
id: str, |
| 2235 |
*, |
| 2236 |
session_id: typing.Optional[str] = OMIT, |
| 2237 |
preserve_refresh_tokens: typing.Optional[bool] = OMIT, |
| 2238 |
request_options: typing.Optional[RequestOptions] = None, |
| 2239 |
) -> AsyncHttpResponse[None]: |
| 2240 |
""" |
| 2241 |
Revokes selected resources related to a user (sessions, refresh tokens, ...). |
| 2242 |
|
| 2243 |
Parameters |
| 2244 |
---------- |
| 2245 |
id : str |
| 2246 |
ID of the user. |
| 2247 |
|
| 2248 |
session_id : typing.Optional[str] |
| 2249 |
ID of the session to revoke. |
| 2250 |
|
| 2251 |
preserve_refresh_tokens : typing.Optional[bool] |
| 2252 |
Whether to preserve the refresh tokens associated with the session. |
| 2253 |
|
| 2254 |
request_options : typing.Optional[RequestOptions] |
| 2255 |
Request-specific configuration. |
| 2256 |
|
| 2257 |
Returns |
| 2258 |
------- |
| 2259 |
AsyncHttpResponse[None] |
| 2260 |
""" |
| 2261 |
_response = await self._client_wrapper.httpx_client.request( |
| 2262 |
f"users/{encode_path_param(id)}/revoke-access", |
| 2263 |
method="POST", |
| 2264 |
json={ |
| 2265 |
"session_id": session_id, |
| 2266 |
"preserve_refresh_tokens": preserve_refresh_tokens, |
| 2267 |
}, |
| 2268 |
headers={ |
| 2269 |
"content-type": "application/json", |
| 2270 |
}, |
| 2271 |
request_options=request_options, |
| 2272 |
omit=OMIT, |
| 2273 |
) |
| 2274 |
try: |
| 2275 |
if 200 <= _response.status_code < 300: |
| 2276 |
return AsyncHttpResponse(response=_response, data=None) |
| 2277 |
if _response.status_code == 400: |
| 2278 |
raise BadRequestError( |
| 2279 |
headers=dict(_response.headers), |
| 2280 |
body=typing.cast( |
| 2281 |
typing.Any, |
| 2282 |
parse_obj_as( |
| 2283 |
type_=typing.Any, |
| 2284 |
object_=_response.json(), |
| 2285 |
), |
| 2286 |
), |
| 2287 |
) |
| 2288 |
if _response.status_code == 401: |
| 2289 |
raise UnauthorizedError( |
| 2290 |
headers=dict(_response.headers), |
| 2291 |
body=typing.cast( |
| 2292 |
typing.Any, |
| 2293 |
parse_obj_as( |
| 2294 |
type_=typing.Any, |
| 2295 |
object_=_response.json(), |
| 2296 |
), |
| 2297 |
), |
| 2298 |
) |
| 2299 |
if _response.status_code == 403: |
| 2300 |
raise ForbiddenError( |
| 2301 |
headers=dict(_response.headers), |
| 2302 |
body=typing.cast( |
| 2303 |
typing.Any, |
| 2304 |
parse_obj_as( |
| 2305 |
type_=typing.Any, |
| 2306 |
object_=_response.json(), |
| 2307 |
), |
| 2308 |
), |
| 2309 |
) |
| 2310 |
if _response.status_code == 429: |
| 2311 |
raise TooManyRequestsError( |
| 2312 |
headers=dict(_response.headers), |
| 2313 |
body=typing.cast( |
| 2314 |
typing.Any, |
| 2315 |
parse_obj_as( |
| 2316 |
type_=typing.Any, |
| 2317 |
object_=_response.json(), |
| 2318 |
), |
| 2319 |
), |
| 2320 |
) |
| 2321 |
_response_json = _response.json() |
| 2322 |
except JSONDecodeError: |
| 2323 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 2324 |
except ValidationError as e: |
| 2325 |
raise ParsingError( |
| 2326 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 2327 |
) |
| 2328 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |