Debian Codegraph @

src/auth0/management/device_credentials/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.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.too_many_requests_error import TooManyRequestsError
18 from ..errors.unauthorized_error import UnauthorizedError
19 from ..types.create_public_key_device_credential_response_content import CreatePublicKeyDeviceCredentialResponseContent
20 from ..types.device_credential import DeviceCredential
21 from ..types.device_credential_public_key_type_enum import DeviceCredentialPublicKeyTypeEnum
22 from ..types.device_credential_type_enum import DeviceCredentialTypeEnum
23 from ..types.list_device_credentials_offset_paginated_response_content import (
24 ListDeviceCredentialsOffsetPaginatedResponseContent,
25 )
26 from pydantic import ValidationError
27
28 # this is used as the default value for optional parameters
29 OMIT = typing.cast(typing.Any, ...)
30
31
32 class RawDeviceCredentialsClient:
33 def __init__(self, *, client_wrapper: SyncClientWrapper):
34 self._client_wrapper = client_wrapper
35
36 def list(
37 self,
38 *,
39 page: typing.Optional[int] = 0,
40 per_page: typing.Optional[int] = 50,
41 include_totals: typing.Optional[bool] = True,
42 fields: typing.Optional[str] = None,
43 include_fields: typing.Optional[bool] = None,
44 user_id: typing.Optional[str] = None,
45 client_id: typing.Optional[str] = None,
46 type: typing.Optional[DeviceCredentialTypeEnum] = None,
47 request_options: typing.Optional[RequestOptions] = None,
48 ) -> SyncPager[DeviceCredential, ListDeviceCredentialsOffsetPaginatedResponseContent]:
49 """
50 Retrieve device credential information (`public_key`, `refresh_token`, or `rotating_refresh_token`) associated with a specific user.
51
52 Parameters
53 ----------
54 page : typing.Optional[int]
55 Page index of the results to return. First page is 0.
56
57 per_page : typing.Optional[int]
58 Number of results per page. There is a maximum of 1000 results allowed from this endpoint.
59
60 include_totals : typing.Optional[bool]
61 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
62
63 fields : typing.Optional[str]
64 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.
65
66 include_fields : typing.Optional[bool]
67 Whether specified fields are to be included (true) or excluded (false).
68
69 user_id : typing.Optional[str]
70 user_id of the devices to retrieve.
71
72 client_id : typing.Optional[str]
73 client_id of the devices to retrieve.
74
75 type : typing.Optional[DeviceCredentialTypeEnum]
76 Type of credentials to retrieve. Must be `public_key`, `refresh_token` or `rotating_refresh_token`. The property will default to `refresh_token` when paging is requested
77
78 request_options : typing.Optional[RequestOptions]
79 Request-specific configuration.
80
81 Returns
82 -------
83 SyncPager[DeviceCredential, ListDeviceCredentialsOffsetPaginatedResponseContent]
84 Device credentials successfully retrieved.
85 """
86 page = page if page is not None else 0
87
88 _response = self._client_wrapper.httpx_client.request(
89 "device-credentials",
90 method="GET",
91 params={
92 "page": page,
93 "per_page": per_page,
94 "include_totals": include_totals,
95 "fields": fields,
96 "include_fields": include_fields,
97 "user_id": user_id,
98 "client_id": client_id,
99 "type": type,
100 },
101 request_options=request_options,
102 )
103 try:
104 if 200 <= _response.status_code < 300:
105 _parsed_response = typing.cast(
106 ListDeviceCredentialsOffsetPaginatedResponseContent,
107 parse_obj_as(
108 type_=ListDeviceCredentialsOffsetPaginatedResponseContent, # type: ignore
109 object_=_response.json(),
110 ),
111 )
112 _items = _parsed_response.device_credentials
113 _has_next = len(_items or []) > 0
114 _get_next = lambda: self.list(
115 page=page + 1,
116 per_page=per_page,
117 include_totals=include_totals,
118 fields=fields,
119 include_fields=include_fields,
120 user_id=user_id,
121 client_id=client_id,
122 type=type,
123 request_options=request_options,
124 )
125 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
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 == 429:
160 raise TooManyRequestsError(
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 _response_json = _response.json()
171 except JSONDecodeError:
172 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
173 except ValidationError as e:
174 raise ParsingError(
175 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
176 )
177 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
178
179 def create_public_key(
180 self,
181 *,
182 device_name: str,
183 type: DeviceCredentialPublicKeyTypeEnum,
184 value: str,
185 device_id: str,
186 client_id: typing.Optional[str] = OMIT,
187 request_options: typing.Optional[RequestOptions] = None,
188 ) -> HttpResponse[CreatePublicKeyDeviceCredentialResponseContent]:
189 """
190 Create a device credential public key to manage refresh token rotation for a given `user_id`. Device Credentials APIs are designed for ad-hoc administrative use only and paging is by default enabled for GET requests.
191
192 When refresh token rotation is enabled, the endpoint becomes consistent. For more information, read [Signing Keys](https://auth0.com/docs/get-started/tenant-settings/signing-keys).
193
194 Parameters
195 ----------
196 device_name : str
197 Name for this device easily recognized by owner.
198
199 type : DeviceCredentialPublicKeyTypeEnum
200
201 value : str
202 Base64 encoded string containing the credential.
203
204 device_id : str
205 Unique identifier for the device. Recommend using <a href="http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID">Android_ID</a> on Android and <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/index.html#//apple_ref/occ/instp/UIDevice/identifierForVendor">identifierForVendor</a>.
206
207 client_id : typing.Optional[str]
208 client_id of the client (application) this credential is for.
209
210 request_options : typing.Optional[RequestOptions]
211 Request-specific configuration.
212
213 Returns
214 -------
215 HttpResponse[CreatePublicKeyDeviceCredentialResponseContent]
216 Device credentials successfully created.
217 """
218 _response = self._client_wrapper.httpx_client.request(
219 "device-credentials",
220 method="POST",
221 json={
222 "device_name": device_name,
223 "type": type,
224 "value": value,
225 "device_id": device_id,
226 "client_id": client_id,
227 },
228 headers={
229 "content-type": "application/json",
230 },
231 request_options=request_options,
232 omit=OMIT,
233 )
234 try:
235 if 200 <= _response.status_code < 300:
236 _data = typing.cast(
237 CreatePublicKeyDeviceCredentialResponseContent,
238 parse_obj_as(
239 type_=CreatePublicKeyDeviceCredentialResponseContent, # type: ignore
240 object_=_response.json(),
241 ),
242 )
243 return HttpResponse(response=_response, data=_data)
244 if _response.status_code == 400:
245 raise BadRequestError(
246 headers=dict(_response.headers),
247 body=typing.cast(
248 typing.Any,
249 parse_obj_as(
250 type_=typing.Any, # type: ignore
251 object_=_response.json(),
252 ),
253 ),
254 )
255 if _response.status_code == 401:
256 raise UnauthorizedError(
257 headers=dict(_response.headers),
258 body=typing.cast(
259 typing.Any,
260 parse_obj_as(
261 type_=typing.Any, # type: ignore
262 object_=_response.json(),
263 ),
264 ),
265 )
266 if _response.status_code == 403:
267 raise ForbiddenError(
268 headers=dict(_response.headers),
269 body=typing.cast(
270 typing.Any,
271 parse_obj_as(
272 type_=typing.Any, # type: ignore
273 object_=_response.json(),
274 ),
275 ),
276 )
277 if _response.status_code == 409:
278 raise ConflictError(
279 headers=dict(_response.headers),
280 body=typing.cast(
281 typing.Any,
282 parse_obj_as(
283 type_=typing.Any, # type: ignore
284 object_=_response.json(),
285 ),
286 ),
287 )
288 if _response.status_code == 429:
289 raise TooManyRequestsError(
290 headers=dict(_response.headers),
291 body=typing.cast(
292 typing.Any,
293 parse_obj_as(
294 type_=typing.Any, # type: ignore
295 object_=_response.json(),
296 ),
297 ),
298 )
299 _response_json = _response.json()
300 except JSONDecodeError:
301 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
302 except ValidationError as e:
303 raise ParsingError(
304 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
305 )
306 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
307
308 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
309 """
310 Permanently delete a device credential (such as a refresh token or public key) with the given ID.
311
312 Parameters
313 ----------
314 id : str
315 ID of the credential to delete.
316
317 request_options : typing.Optional[RequestOptions]
318 Request-specific configuration.
319
320 Returns
321 -------
322 HttpResponse[None]
323 """
324 _response = self._client_wrapper.httpx_client.request(
325 f"device-credentials/{encode_path_param(id)}",
326 method="DELETE",
327 request_options=request_options,
328 )
329 try:
330 if 200 <= _response.status_code < 300:
331 return HttpResponse(response=_response, data=None)
332 if _response.status_code == 400:
333 raise BadRequestError(
334 headers=dict(_response.headers),
335 body=typing.cast(
336 typing.Any,
337 parse_obj_as(
338 type_=typing.Any, # type: ignore
339 object_=_response.json(),
340 ),
341 ),
342 )
343 if _response.status_code == 401:
344 raise UnauthorizedError(
345 headers=dict(_response.headers),
346 body=typing.cast(
347 typing.Any,
348 parse_obj_as(
349 type_=typing.Any, # type: ignore
350 object_=_response.json(),
351 ),
352 ),
353 )
354 if _response.status_code == 403:
355 raise ForbiddenError(
356 headers=dict(_response.headers),
357 body=typing.cast(
358 typing.Any,
359 parse_obj_as(
360 type_=typing.Any, # type: ignore
361 object_=_response.json(),
362 ),
363 ),
364 )
365 if _response.status_code == 429:
366 raise TooManyRequestsError(
367 headers=dict(_response.headers),
368 body=typing.cast(
369 typing.Any,
370 parse_obj_as(
371 type_=typing.Any, # type: ignore
372 object_=_response.json(),
373 ),
374 ),
375 )
376 _response_json = _response.json()
377 except JSONDecodeError:
378 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
379 except ValidationError as e:
380 raise ParsingError(
381 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
382 )
383 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
384
385
386 class AsyncRawDeviceCredentialsClient:
387 def __init__(self, *, client_wrapper: AsyncClientWrapper):
388 self._client_wrapper = client_wrapper
389
390 async def list(
391 self,
392 *,
393 page: typing.Optional[int] = 0,
394 per_page: typing.Optional[int] = 50,
395 include_totals: typing.Optional[bool] = True,
396 fields: typing.Optional[str] = None,
397 include_fields: typing.Optional[bool] = None,
398 user_id: typing.Optional[str] = None,
399 client_id: typing.Optional[str] = None,
400 type: typing.Optional[DeviceCredentialTypeEnum] = None,
401 request_options: typing.Optional[RequestOptions] = None,
402 ) -> AsyncPager[DeviceCredential, ListDeviceCredentialsOffsetPaginatedResponseContent]:
403 """
404 Retrieve device credential information (`public_key`, `refresh_token`, or `rotating_refresh_token`) associated with a specific user.
405
406 Parameters
407 ----------
408 page : typing.Optional[int]
409 Page index of the results to return. First page is 0.
410
411 per_page : typing.Optional[int]
412 Number of results per page. There is a maximum of 1000 results allowed from this endpoint.
413
414 include_totals : typing.Optional[bool]
415 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
416
417 fields : typing.Optional[str]
418 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.
419
420 include_fields : typing.Optional[bool]
421 Whether specified fields are to be included (true) or excluded (false).
422
423 user_id : typing.Optional[str]
424 user_id of the devices to retrieve.
425
426 client_id : typing.Optional[str]
427 client_id of the devices to retrieve.
428
429 type : typing.Optional[DeviceCredentialTypeEnum]
430 Type of credentials to retrieve. Must be `public_key`, `refresh_token` or `rotating_refresh_token`. The property will default to `refresh_token` when paging is requested
431
432 request_options : typing.Optional[RequestOptions]
433 Request-specific configuration.
434
435 Returns
436 -------
437 AsyncPager[DeviceCredential, ListDeviceCredentialsOffsetPaginatedResponseContent]
438 Device credentials successfully retrieved.
439 """
440 page = page if page is not None else 0
441
442 _response = await self._client_wrapper.httpx_client.request(
443 "device-credentials",
444 method="GET",
445 params={
446 "page": page,
447 "per_page": per_page,
448 "include_totals": include_totals,
449 "fields": fields,
450 "include_fields": include_fields,
451 "user_id": user_id,
452 "client_id": client_id,
453 "type": type,
454 },
455 request_options=request_options,
456 )
457 try:
458 if 200 <= _response.status_code < 300:
459 _parsed_response = typing.cast(
460 ListDeviceCredentialsOffsetPaginatedResponseContent,
461 parse_obj_as(
462 type_=ListDeviceCredentialsOffsetPaginatedResponseContent, # type: ignore
463 object_=_response.json(),
464 ),
465 )
466 _items = _parsed_response.device_credentials
467 _has_next = len(_items or []) > 0
468
469 async def _get_next():
470 return await self.list(
471 page=page + 1,
472 per_page=per_page,
473 include_totals=include_totals,
474 fields=fields,
475 include_fields=include_fields,
476 user_id=user_id,
477 client_id=client_id,
478 type=type,
479 request_options=request_options,
480 )
481
482 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
483 if _response.status_code == 400:
484 raise BadRequestError(
485 headers=dict(_response.headers),
486 body=typing.cast(
487 typing.Any,
488 parse_obj_as(
489 type_=typing.Any, # type: ignore
490 object_=_response.json(),
491 ),
492 ),
493 )
494 if _response.status_code == 401:
495 raise UnauthorizedError(
496 headers=dict(_response.headers),
497 body=typing.cast(
498 typing.Any,
499 parse_obj_as(
500 type_=typing.Any, # type: ignore
501 object_=_response.json(),
502 ),
503 ),
504 )
505 if _response.status_code == 403:
506 raise ForbiddenError(
507 headers=dict(_response.headers),
508 body=typing.cast(
509 typing.Any,
510 parse_obj_as(
511 type_=typing.Any, # type: ignore
512 object_=_response.json(),
513 ),
514 ),
515 )
516 if _response.status_code == 429:
517 raise TooManyRequestsError(
518 headers=dict(_response.headers),
519 body=typing.cast(
520 typing.Any,
521 parse_obj_as(
522 type_=typing.Any, # type: ignore
523 object_=_response.json(),
524 ),
525 ),
526 )
527 _response_json = _response.json()
528 except JSONDecodeError:
529 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
530 except ValidationError as e:
531 raise ParsingError(
532 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
533 )
534 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
535
536 async def create_public_key(
537 self,
538 *,
539 device_name: str,
540 type: DeviceCredentialPublicKeyTypeEnum,
541 value: str,
542 device_id: str,
543 client_id: typing.Optional[str] = OMIT,
544 request_options: typing.Optional[RequestOptions] = None,
545 ) -> AsyncHttpResponse[CreatePublicKeyDeviceCredentialResponseContent]:
546 """
547 Create a device credential public key to manage refresh token rotation for a given `user_id`. Device Credentials APIs are designed for ad-hoc administrative use only and paging is by default enabled for GET requests.
548
549 When refresh token rotation is enabled, the endpoint becomes consistent. For more information, read [Signing Keys](https://auth0.com/docs/get-started/tenant-settings/signing-keys).
550
551 Parameters
552 ----------
553 device_name : str
554 Name for this device easily recognized by owner.
555
556 type : DeviceCredentialPublicKeyTypeEnum
557
558 value : str
559 Base64 encoded string containing the credential.
560
561 device_id : str
562 Unique identifier for the device. Recommend using <a href="http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID">Android_ID</a> on Android and <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/index.html#//apple_ref/occ/instp/UIDevice/identifierForVendor">identifierForVendor</a>.
563
564 client_id : typing.Optional[str]
565 client_id of the client (application) this credential is for.
566
567 request_options : typing.Optional[RequestOptions]
568 Request-specific configuration.
569
570 Returns
571 -------
572 AsyncHttpResponse[CreatePublicKeyDeviceCredentialResponseContent]
573 Device credentials successfully created.
574 """
575 _response = await self._client_wrapper.httpx_client.request(
576 "device-credentials",
577 method="POST",
578 json={
579 "device_name": device_name,
580 "type": type,
581 "value": value,
582 "device_id": device_id,
583 "client_id": client_id,
584 },
585 headers={
586 "content-type": "application/json",
587 },
588 request_options=request_options,
589 omit=OMIT,
590 )
591 try:
592 if 200 <= _response.status_code < 300:
593 _data = typing.cast(
594 CreatePublicKeyDeviceCredentialResponseContent,
595 parse_obj_as(
596 type_=CreatePublicKeyDeviceCredentialResponseContent, # type: ignore
597 object_=_response.json(),
598 ),
599 )
600 return AsyncHttpResponse(response=_response, data=_data)
601 if _response.status_code == 400:
602 raise BadRequestError(
603 headers=dict(_response.headers),
604 body=typing.cast(
605 typing.Any,
606 parse_obj_as(
607 type_=typing.Any, # type: ignore
608 object_=_response.json(),
609 ),
610 ),
611 )
612 if _response.status_code == 401:
613 raise UnauthorizedError(
614 headers=dict(_response.headers),
615 body=typing.cast(
616 typing.Any,
617 parse_obj_as(
618 type_=typing.Any, # type: ignore
619 object_=_response.json(),
620 ),
621 ),
622 )
623 if _response.status_code == 403:
624 raise ForbiddenError(
625 headers=dict(_response.headers),
626 body=typing.cast(
627 typing.Any,
628 parse_obj_as(
629 type_=typing.Any, # type: ignore
630 object_=_response.json(),
631 ),
632 ),
633 )
634 if _response.status_code == 409:
635 raise ConflictError(
636 headers=dict(_response.headers),
637 body=typing.cast(
638 typing.Any,
639 parse_obj_as(
640 type_=typing.Any, # type: ignore
641 object_=_response.json(),
642 ),
643 ),
644 )
645 if _response.status_code == 429:
646 raise TooManyRequestsError(
647 headers=dict(_response.headers),
648 body=typing.cast(
649 typing.Any,
650 parse_obj_as(
651 type_=typing.Any, # type: ignore
652 object_=_response.json(),
653 ),
654 ),
655 )
656 _response_json = _response.json()
657 except JSONDecodeError:
658 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
659 except ValidationError as e:
660 raise ParsingError(
661 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
662 )
663 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
664
665 async def delete(
666 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
667 ) -> AsyncHttpResponse[None]:
668 """
669 Permanently delete a device credential (such as a refresh token or public key) with the given ID.
670
671 Parameters
672 ----------
673 id : str
674 ID of the credential to delete.
675
676 request_options : typing.Optional[RequestOptions]
677 Request-specific configuration.
678
679 Returns
680 -------
681 AsyncHttpResponse[None]
682 """
683 _response = await self._client_wrapper.httpx_client.request(
684 f"device-credentials/{encode_path_param(id)}",
685 method="DELETE",
686 request_options=request_options,
687 )
688 try:
689 if 200 <= _response.status_code < 300:
690 return AsyncHttpResponse(response=_response, data=None)
691 if _response.status_code == 400:
692 raise BadRequestError(
693 headers=dict(_response.headers),
694 body=typing.cast(
695 typing.Any,
696 parse_obj_as(
697 type_=typing.Any, # type: ignore
698 object_=_response.json(),
699 ),
700 ),
701 )
702 if _response.status_code == 401:
703 raise UnauthorizedError(
704 headers=dict(_response.headers),
705 body=typing.cast(
706 typing.Any,
707 parse_obj_as(
708 type_=typing.Any, # type: ignore
709 object_=_response.json(),
710 ),
711 ),
712 )
713 if _response.status_code == 403:
714 raise ForbiddenError(
715 headers=dict(_response.headers),
716 body=typing.cast(
717 typing.Any,
718 parse_obj_as(
719 type_=typing.Any, # type: ignore
720 object_=_response.json(),
721 ),
722 ),
723 )
724 if _response.status_code == 429:
725 raise TooManyRequestsError(
726 headers=dict(_response.headers),
727 body=typing.cast(
728 typing.Any,
729 parse_obj_as(
730 type_=typing.Any, # type: ignore
731 object_=_response.json(),
732 ),
733 ),
734 )
735 _response_json = _response.json()
736 except JSONDecodeError:
737 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
738 except ValidationError as e:
739 raise ParsingError(
740 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
741 )
742 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)