Debian Codegraph @

src/auth0/management/users/identities/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
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 ...core.serialization import convert_and_respect_annotation_metadata
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.too_many_requests_error import TooManyRequestsError
18 from ...errors.unauthorized_error import UnauthorizedError
19 from ...types.delete_user_identity_response_content import DeleteUserIdentityResponseContent
20 from ...types.user_id import UserId
21 from ...types.user_identity import UserIdentity
22 from ...types.user_identity_provider_enum import UserIdentityProviderEnum
23 from pydantic import ValidationError
24
25 # this is used as the default value for optional parameters
26 OMIT = typing.cast(typing.Any, ...)
27
28
29 class RawIdentitiesClient:
30 def __init__(self, *, client_wrapper: SyncClientWrapper):
31 self._client_wrapper = client_wrapper
32
33 def link(
34 self,
35 id: str,
36 *,
37 provider: typing.Optional[UserIdentityProviderEnum] = OMIT,
38 connection_id: typing.Optional[str] = OMIT,
39 user_id: typing.Optional[UserId] = OMIT,
40 link_with: typing.Optional[str] = OMIT,
41 request_options: typing.Optional[RequestOptions] = None,
42 ) -> HttpResponse[typing.List[UserIdentity]]:
43 """
44 Link two user accounts together forming a primary and secondary relationship. On successful linking, the endpoint returns the new array of the primary account identities.
45
46 Note: There are two ways of invoking the endpoint:
47
48 - With the authenticated primary account's JWT in the Authorization header, which has the `update:current_user_identities` scope:
49
50 ```http
51 POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities
52 Authorization: "Bearer PRIMARY_ACCOUNT_JWT"
53 {
54 "link_with": "SECONDARY_ACCOUNT_JWT"
55 }
56 ```
57
58 In this case, only the `link_with` param is required in the body, which also contains the JWT obtained upon the secondary account's authentication.
59
60 - With a token generated by the API V2 containing the `update:users` scope:
61
62 ```http
63 POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities
64 Authorization: "Bearer YOUR_API_V2_TOKEN"
65 {
66 "provider": "SECONDARY_ACCOUNT_PROVIDER",
67 "connection_id": "SECONDARY_ACCOUNT_CONNECTION_ID(OPTIONAL)",
68 "user_id": "SECONDARY_ACCOUNT_USER_ID"
69 }
70 ```
71
72 In this case you need to send `provider` and `user_id` in the body. Optionally you can also send the `connection_id` param which is suitable for identifying a particular database connection for the 'auth0' provider.
73
74 Parameters
75 ----------
76 id : str
77 ID of the primary user account to link a second user account to.
78
79 provider : typing.Optional[UserIdentityProviderEnum]
80 Identity provider of the secondary user account being linked.
81
82 connection_id : typing.Optional[str]
83 connection_id of the secondary user account being linked when more than one `auth0` database provider exists.
84
85 user_id : typing.Optional[UserId]
86 user_id of the secondary user account being linked.
87
88 link_with : typing.Optional[str]
89 JWT for the secondary account being linked. If sending this parameter, `provider`, `user_id`, and `connection_id` must not be sent.
90
91 request_options : typing.Optional[RequestOptions]
92 Request-specific configuration.
93
94 Returns
95 -------
96 HttpResponse[typing.List[UserIdentity]]
97 Identity successfully added.
98 """
99 _response = self._client_wrapper.httpx_client.request(
100 f"users/{encode_path_param(id)}/identities",
101 method="POST",
102 json={
103 "provider": provider,
104 "connection_id": connection_id,
105 "user_id": convert_and_respect_annotation_metadata(
106 object_=user_id, annotation=UserId, direction="write"
107 ),
108 "link_with": link_with,
109 },
110 headers={
111 "content-type": "application/json",
112 },
113 request_options=request_options,
114 omit=OMIT,
115 )
116 try:
117 if 200 <= _response.status_code < 300:
118 _data = typing.cast(
119 typing.List[UserIdentity],
120 parse_obj_as(
121 type_=typing.List[UserIdentity], # type: ignore
122 object_=_response.json(),
123 ),
124 )
125 return HttpResponse(response=_response, data=_data)
126 if _response.status_code == 400:
127 raise BadRequestError(
128 headers=dict(_response.headers),
129 body=typing.cast(
130 typing.Any,
131 parse_obj_as(
132 type_=typing.Any, # type: ignore
133 object_=_response.json(),
134 ),
135 ),
136 )
137 if _response.status_code == 401:
138 raise UnauthorizedError(
139 headers=dict(_response.headers),
140 body=typing.cast(
141 typing.Any,
142 parse_obj_as(
143 type_=typing.Any, # type: ignore
144 object_=_response.json(),
145 ),
146 ),
147 )
148 if _response.status_code == 403:
149 raise ForbiddenError(
150 headers=dict(_response.headers),
151 body=typing.cast(
152 typing.Any,
153 parse_obj_as(
154 type_=typing.Any, # type: ignore
155 object_=_response.json(),
156 ),
157 ),
158 )
159 if _response.status_code == 409:
160 raise ConflictError(
161 headers=dict(_response.headers),
162 body=typing.cast(
163 typing.Any,
164 parse_obj_as(
165 type_=typing.Any, # type: ignore
166 object_=_response.json(),
167 ),
168 ),
169 )
170 if _response.status_code == 429:
171 raise TooManyRequestsError(
172 headers=dict(_response.headers),
173 body=typing.cast(
174 typing.Any,
175 parse_obj_as(
176 type_=typing.Any, # type: ignore
177 object_=_response.json(),
178 ),
179 ),
180 )
181 _response_json = _response.json()
182 except JSONDecodeError:
183 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
184 except ValidationError as e:
185 raise ParsingError(
186 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
187 )
188 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
189
190 def delete(
191 self,
192 id: str,
193 provider: UserIdentityProviderEnum,
194 user_id: str,
195 *,
196 request_options: typing.Optional[RequestOptions] = None,
197 ) -> HttpResponse[DeleteUserIdentityResponseContent]:
198 """
199 Unlink a specific secondary account from a target user. This action requires the ID of both the target user and the secondary account.
200
201 Unlinking the secondary account removes it from the identities array of the target user and creates a new standalone profile for the secondary account. To learn more, review [Unlink User Accounts](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/unlink-user-accounts).
202
203 Parameters
204 ----------
205 id : str
206 ID of the primary user account.
207
208 provider : UserIdentityProviderEnum
209 Identity provider name of the secondary linked account (e.g. `google-oauth2`).
210
211 user_id : str
212 ID of the secondary linked account (e.g. `123456789081523216417` part after the `|` in `google-oauth2|123456789081523216417`).
213
214 request_options : typing.Optional[RequestOptions]
215 Request-specific configuration.
216
217 Returns
218 -------
219 HttpResponse[DeleteUserIdentityResponseContent]
220 User identity successfully unlinked.
221 """
222 _response = self._client_wrapper.httpx_client.request(
223 f"users/{encode_path_param(id)}/identities/{encode_path_param(provider)}/{encode_path_param(user_id)}",
224 method="DELETE",
225 request_options=request_options,
226 )
227 try:
228 if 200 <= _response.status_code < 300:
229 _data = typing.cast(
230 DeleteUserIdentityResponseContent,
231 parse_obj_as(
232 type_=DeleteUserIdentityResponseContent, # type: ignore
233 object_=_response.json(),
234 ),
235 )
236 return HttpResponse(response=_response, data=_data)
237 if _response.status_code == 400:
238 raise BadRequestError(
239 headers=dict(_response.headers),
240 body=typing.cast(
241 typing.Any,
242 parse_obj_as(
243 type_=typing.Any, # type: ignore
244 object_=_response.json(),
245 ),
246 ),
247 )
248 if _response.status_code == 401:
249 raise UnauthorizedError(
250 headers=dict(_response.headers),
251 body=typing.cast(
252 typing.Any,
253 parse_obj_as(
254 type_=typing.Any, # type: ignore
255 object_=_response.json(),
256 ),
257 ),
258 )
259 if _response.status_code == 403:
260 raise ForbiddenError(
261 headers=dict(_response.headers),
262 body=typing.cast(
263 typing.Any,
264 parse_obj_as(
265 type_=typing.Any, # type: ignore
266 object_=_response.json(),
267 ),
268 ),
269 )
270 if _response.status_code == 429:
271 raise TooManyRequestsError(
272 headers=dict(_response.headers),
273 body=typing.cast(
274 typing.Any,
275 parse_obj_as(
276 type_=typing.Any, # type: ignore
277 object_=_response.json(),
278 ),
279 ),
280 )
281 _response_json = _response.json()
282 except JSONDecodeError:
283 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
284 except ValidationError as e:
285 raise ParsingError(
286 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
287 )
288 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
289
290
291 class AsyncRawIdentitiesClient:
292 def __init__(self, *, client_wrapper: AsyncClientWrapper):
293 self._client_wrapper = client_wrapper
294
295 async def link(
296 self,
297 id: str,
298 *,
299 provider: typing.Optional[UserIdentityProviderEnum] = OMIT,
300 connection_id: typing.Optional[str] = OMIT,
301 user_id: typing.Optional[UserId] = OMIT,
302 link_with: typing.Optional[str] = OMIT,
303 request_options: typing.Optional[RequestOptions] = None,
304 ) -> AsyncHttpResponse[typing.List[UserIdentity]]:
305 """
306 Link two user accounts together forming a primary and secondary relationship. On successful linking, the endpoint returns the new array of the primary account identities.
307
308 Note: There are two ways of invoking the endpoint:
309
310 - With the authenticated primary account's JWT in the Authorization header, which has the `update:current_user_identities` scope:
311
312 ```http
313 POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities
314 Authorization: "Bearer PRIMARY_ACCOUNT_JWT"
315 {
316 "link_with": "SECONDARY_ACCOUNT_JWT"
317 }
318 ```
319
320 In this case, only the `link_with` param is required in the body, which also contains the JWT obtained upon the secondary account's authentication.
321
322 - With a token generated by the API V2 containing the `update:users` scope:
323
324 ```http
325 POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities
326 Authorization: "Bearer YOUR_API_V2_TOKEN"
327 {
328 "provider": "SECONDARY_ACCOUNT_PROVIDER",
329 "connection_id": "SECONDARY_ACCOUNT_CONNECTION_ID(OPTIONAL)",
330 "user_id": "SECONDARY_ACCOUNT_USER_ID"
331 }
332 ```
333
334 In this case you need to send `provider` and `user_id` in the body. Optionally you can also send the `connection_id` param which is suitable for identifying a particular database connection for the 'auth0' provider.
335
336 Parameters
337 ----------
338 id : str
339 ID of the primary user account to link a second user account to.
340
341 provider : typing.Optional[UserIdentityProviderEnum]
342 Identity provider of the secondary user account being linked.
343
344 connection_id : typing.Optional[str]
345 connection_id of the secondary user account being linked when more than one `auth0` database provider exists.
346
347 user_id : typing.Optional[UserId]
348 user_id of the secondary user account being linked.
349
350 link_with : typing.Optional[str]
351 JWT for the secondary account being linked. If sending this parameter, `provider`, `user_id`, and `connection_id` must not be sent.
352
353 request_options : typing.Optional[RequestOptions]
354 Request-specific configuration.
355
356 Returns
357 -------
358 AsyncHttpResponse[typing.List[UserIdentity]]
359 Identity successfully added.
360 """
361 _response = await self._client_wrapper.httpx_client.request(
362 f"users/{encode_path_param(id)}/identities",
363 method="POST",
364 json={
365 "provider": provider,
366 "connection_id": connection_id,
367 "user_id": convert_and_respect_annotation_metadata(
368 object_=user_id, annotation=UserId, direction="write"
369 ),
370 "link_with": link_with,
371 },
372 headers={
373 "content-type": "application/json",
374 },
375 request_options=request_options,
376 omit=OMIT,
377 )
378 try:
379 if 200 <= _response.status_code < 300:
380 _data = typing.cast(
381 typing.List[UserIdentity],
382 parse_obj_as(
383 type_=typing.List[UserIdentity], # type: ignore
384 object_=_response.json(),
385 ),
386 )
387 return AsyncHttpResponse(response=_response, data=_data)
388 if _response.status_code == 400:
389 raise BadRequestError(
390 headers=dict(_response.headers),
391 body=typing.cast(
392 typing.Any,
393 parse_obj_as(
394 type_=typing.Any, # type: ignore
395 object_=_response.json(),
396 ),
397 ),
398 )
399 if _response.status_code == 401:
400 raise UnauthorizedError(
401 headers=dict(_response.headers),
402 body=typing.cast(
403 typing.Any,
404 parse_obj_as(
405 type_=typing.Any, # type: ignore
406 object_=_response.json(),
407 ),
408 ),
409 )
410 if _response.status_code == 403:
411 raise ForbiddenError(
412 headers=dict(_response.headers),
413 body=typing.cast(
414 typing.Any,
415 parse_obj_as(
416 type_=typing.Any, # type: ignore
417 object_=_response.json(),
418 ),
419 ),
420 )
421 if _response.status_code == 409:
422 raise ConflictError(
423 headers=dict(_response.headers),
424 body=typing.cast(
425 typing.Any,
426 parse_obj_as(
427 type_=typing.Any, # type: ignore
428 object_=_response.json(),
429 ),
430 ),
431 )
432 if _response.status_code == 429:
433 raise TooManyRequestsError(
434 headers=dict(_response.headers),
435 body=typing.cast(
436 typing.Any,
437 parse_obj_as(
438 type_=typing.Any, # type: ignore
439 object_=_response.json(),
440 ),
441 ),
442 )
443 _response_json = _response.json()
444 except JSONDecodeError:
445 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
446 except ValidationError as e:
447 raise ParsingError(
448 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
449 )
450 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
451
452 async def delete(
453 self,
454 id: str,
455 provider: UserIdentityProviderEnum,
456 user_id: str,
457 *,
458 request_options: typing.Optional[RequestOptions] = None,
459 ) -> AsyncHttpResponse[DeleteUserIdentityResponseContent]:
460 """
461 Unlink a specific secondary account from a target user. This action requires the ID of both the target user and the secondary account.
462
463 Unlinking the secondary account removes it from the identities array of the target user and creates a new standalone profile for the secondary account. To learn more, review [Unlink User Accounts](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/unlink-user-accounts).
464
465 Parameters
466 ----------
467 id : str
468 ID of the primary user account.
469
470 provider : UserIdentityProviderEnum
471 Identity provider name of the secondary linked account (e.g. `google-oauth2`).
472
473 user_id : str
474 ID of the secondary linked account (e.g. `123456789081523216417` part after the `|` in `google-oauth2|123456789081523216417`).
475
476 request_options : typing.Optional[RequestOptions]
477 Request-specific configuration.
478
479 Returns
480 -------
481 AsyncHttpResponse[DeleteUserIdentityResponseContent]
482 User identity successfully unlinked.
483 """
484 _response = await self._client_wrapper.httpx_client.request(
485 f"users/{encode_path_param(id)}/identities/{encode_path_param(provider)}/{encode_path_param(user_id)}",
486 method="DELETE",
487 request_options=request_options,
488 )
489 try:
490 if 200 <= _response.status_code < 300:
491 _data = typing.cast(
492 DeleteUserIdentityResponseContent,
493 parse_obj_as(
494 type_=DeleteUserIdentityResponseContent, # type: ignore
495 object_=_response.json(),
496 ),
497 )
498 return AsyncHttpResponse(response=_response, data=_data)
499 if _response.status_code == 400:
500 raise BadRequestError(
501 headers=dict(_response.headers),
502 body=typing.cast(
503 typing.Any,
504 parse_obj_as(
505 type_=typing.Any, # type: ignore
506 object_=_response.json(),
507 ),
508 ),
509 )
510 if _response.status_code == 401:
511 raise UnauthorizedError(
512 headers=dict(_response.headers),
513 body=typing.cast(
514 typing.Any,
515 parse_obj_as(
516 type_=typing.Any, # type: ignore
517 object_=_response.json(),
518 ),
519 ),
520 )
521 if _response.status_code == 403:
522 raise ForbiddenError(
523 headers=dict(_response.headers),
524 body=typing.cast(
525 typing.Any,
526 parse_obj_as(
527 type_=typing.Any, # type: ignore
528 object_=_response.json(),
529 ),
530 ),
531 )
532 if _response.status_code == 429:
533 raise TooManyRequestsError(
534 headers=dict(_response.headers),
535 body=typing.cast(
536 typing.Any,
537 parse_obj_as(
538 type_=typing.Any, # type: ignore
539 object_=_response.json(),
540 ),
541 ),
542 )
543 _response_json = _response.json()
544 except JSONDecodeError:
545 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
546 except ValidationError as e:
547 raise ParsingError(
548 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
549 )
550 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)