Debian Codegraph @

src/auth0/management/refresh_tokens/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.forbidden_error import ForbiddenError
16 from ..errors.not_found_error import NotFoundError
17 from ..errors.too_many_requests_error import TooManyRequestsError
18 from ..errors.unauthorized_error import UnauthorizedError
19 from ..types.get_refresh_token_response_content import GetRefreshTokenResponseContent
20 from ..types.get_refresh_tokens_paginated_response_content import GetRefreshTokensPaginatedResponseContent
21 from ..types.refresh_token_metadata import RefreshTokenMetadata
22 from ..types.refresh_token_response_content import RefreshTokenResponseContent
23 from ..types.update_refresh_token_response_content import UpdateRefreshTokenResponseContent
24 from pydantic import ValidationError
25
26 # this is used as the default value for optional parameters
27 OMIT = typing.cast(typing.Any, ...)
28
29
30 class RawRefreshTokensClient:
31 def __init__(self, *, client_wrapper: SyncClientWrapper):
32 self._client_wrapper = client_wrapper
33
34 def list(
35 self,
36 *,
37 user_id: str,
38 client_id: typing.Optional[str] = None,
39 from_: typing.Optional[str] = None,
40 take: typing.Optional[int] = 50,
41 fields: typing.Optional[str] = None,
42 include_fields: typing.Optional[bool] = None,
43 request_options: typing.Optional[RequestOptions] = None,
44 ) -> SyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]:
45 """
46 Retrieve a paginated list of refresh tokens for a specific user, with optional filtering by client ID. Results are sorted by credential_id ascending.
47
48 Parameters
49 ----------
50 user_id : str
51 ID of the user whose refresh tokens to retrieve. Required.
52
53 client_id : typing.Optional[str]
54 Filter results by client ID. Only valid when user_id is provided.
55
56 from_ : typing.Optional[str]
57 An opaque cursor from which to start the selection (exclusive). Expires after 24 hours. Obtained from the next property of a previous response.
58
59 take : typing.Optional[int]
60 Number of results per page. Defaults to 50.
61
62 fields : typing.Optional[str]
63 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.
64
65 include_fields : typing.Optional[bool]
66 Whether specified fields are to be included (true) or excluded (false).
67
68 request_options : typing.Optional[RequestOptions]
69 Request-specific configuration.
70
71 Returns
72 -------
73 SyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]
74 The refresh tokens were retrieved.
75 """
76 _response = self._client_wrapper.httpx_client.request(
77 "refresh-tokens",
78 method="GET",
79 params={
80 "user_id": user_id,
81 "client_id": client_id,
82 "from": from_,
83 "take": take,
84 "fields": fields,
85 "include_fields": include_fields,
86 },
87 request_options=request_options,
88 )
89 try:
90 if 200 <= _response.status_code < 300:
91 _parsed_response = typing.cast(
92 GetRefreshTokensPaginatedResponseContent,
93 parse_obj_as(
94 type_=GetRefreshTokensPaginatedResponseContent, # type: ignore
95 object_=_response.json(),
96 ),
97 )
98 _items = _parsed_response.refresh_tokens
99 _parsed_next = _parsed_response.next
100 _has_next = _parsed_next is not None and _parsed_next != ""
101 _get_next = lambda: self.list(
102 user_id=user_id,
103 client_id=client_id,
104 from_=_parsed_next,
105 take=take,
106 fields=fields,
107 include_fields=include_fields,
108 request_options=request_options,
109 )
110 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
111 if _response.status_code == 400:
112 raise BadRequestError(
113 headers=dict(_response.headers),
114 body=typing.cast(
115 typing.Any,
116 parse_obj_as(
117 type_=typing.Any, # type: ignore
118 object_=_response.json(),
119 ),
120 ),
121 )
122 if _response.status_code == 401:
123 raise UnauthorizedError(
124 headers=dict(_response.headers),
125 body=typing.cast(
126 typing.Any,
127 parse_obj_as(
128 type_=typing.Any, # type: ignore
129 object_=_response.json(),
130 ),
131 ),
132 )
133 if _response.status_code == 403:
134 raise ForbiddenError(
135 headers=dict(_response.headers),
136 body=typing.cast(
137 typing.Any,
138 parse_obj_as(
139 type_=typing.Any, # type: ignore
140 object_=_response.json(),
141 ),
142 ),
143 )
144 if _response.status_code == 404:
145 raise NotFoundError(
146 headers=dict(_response.headers),
147 body=typing.cast(
148 typing.Any,
149 parse_obj_as(
150 type_=typing.Any, # type: ignore
151 object_=_response.json(),
152 ),
153 ),
154 )
155 if _response.status_code == 429:
156 raise TooManyRequestsError(
157 headers=dict(_response.headers),
158 body=typing.cast(
159 typing.Any,
160 parse_obj_as(
161 type_=typing.Any, # type: ignore
162 object_=_response.json(),
163 ),
164 ),
165 )
166 _response_json = _response.json()
167 except JSONDecodeError:
168 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
169 except ValidationError as e:
170 raise ParsingError(
171 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
172 )
173 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
174
175 def revoke(
176 self,
177 *,
178 ids: typing.Optional[typing.Sequence[str]] = OMIT,
179 user_id: typing.Optional[str] = OMIT,
180 client_id: typing.Optional[str] = OMIT,
181 audience: typing.Optional[str] = OMIT,
182 request_options: typing.Optional[RequestOptions] = None,
183 ) -> HttpResponse[None]:
184 """
185 Revoke refresh tokens in bulk by ID list, user, user+client, or user+client+audience.
186
187 Parameters
188 ----------
189 ids : typing.Optional[typing.Sequence[str]]
190 Array of refresh token IDs to revoke. Limited to 100 at a time.
191
192 user_id : typing.Optional[str]
193 Revoke all refresh tokens for this user.
194
195 client_id : typing.Optional[str]
196 Revoke refresh tokens for this client. Must be paired with `user_id`; optionally narrowed further with `audience`.
197
198 audience : typing.Optional[str]
199 Resource server identifier (audience) to scope the revocation. Must be used with both `user_id` and `client_id`.
200
201 request_options : typing.Optional[RequestOptions]
202 Request-specific configuration.
203
204 Returns
205 -------
206 HttpResponse[None]
207 """
208 _response = self._client_wrapper.httpx_client.request(
209 "refresh-tokens/revoke",
210 method="POST",
211 json={
212 "ids": ids,
213 "user_id": user_id,
214 "client_id": client_id,
215 "audience": audience,
216 },
217 headers={
218 "content-type": "application/json",
219 },
220 request_options=request_options,
221 omit=OMIT,
222 )
223 try:
224 if 200 <= _response.status_code < 300:
225 return HttpResponse(response=_response, data=None)
226 if _response.status_code == 400:
227 raise BadRequestError(
228 headers=dict(_response.headers),
229 body=typing.cast(
230 typing.Any,
231 parse_obj_as(
232 type_=typing.Any, # type: ignore
233 object_=_response.json(),
234 ),
235 ),
236 )
237 if _response.status_code == 401:
238 raise UnauthorizedError(
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 == 403:
249 raise ForbiddenError(
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 == 429:
260 raise TooManyRequestsError(
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 _response_json = _response.json()
271 except JSONDecodeError:
272 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
273 except ValidationError as e:
274 raise ParsingError(
275 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
276 )
277 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
278
279 def get(
280 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
281 ) -> HttpResponse[GetRefreshTokenResponseContent]:
282 """
283 Retrieve refresh token information.
284
285 Parameters
286 ----------
287 id : str
288 ID refresh token to retrieve
289
290 request_options : typing.Optional[RequestOptions]
291 Request-specific configuration.
292
293 Returns
294 -------
295 HttpResponse[GetRefreshTokenResponseContent]
296 The refresh token was retrieved
297 """
298 _response = self._client_wrapper.httpx_client.request(
299 f"refresh-tokens/{encode_path_param(id)}",
300 method="GET",
301 request_options=request_options,
302 )
303 try:
304 if 200 <= _response.status_code < 300:
305 _data = typing.cast(
306 GetRefreshTokenResponseContent,
307 parse_obj_as(
308 type_=GetRefreshTokenResponseContent, # type: ignore
309 object_=_response.json(),
310 ),
311 )
312 return HttpResponse(response=_response, data=_data)
313 if _response.status_code == 400:
314 raise BadRequestError(
315 headers=dict(_response.headers),
316 body=typing.cast(
317 typing.Any,
318 parse_obj_as(
319 type_=typing.Any, # type: ignore
320 object_=_response.json(),
321 ),
322 ),
323 )
324 if _response.status_code == 401:
325 raise UnauthorizedError(
326 headers=dict(_response.headers),
327 body=typing.cast(
328 typing.Any,
329 parse_obj_as(
330 type_=typing.Any, # type: ignore
331 object_=_response.json(),
332 ),
333 ),
334 )
335 if _response.status_code == 403:
336 raise ForbiddenError(
337 headers=dict(_response.headers),
338 body=typing.cast(
339 typing.Any,
340 parse_obj_as(
341 type_=typing.Any, # type: ignore
342 object_=_response.json(),
343 ),
344 ),
345 )
346 if _response.status_code == 404:
347 raise NotFoundError(
348 headers=dict(_response.headers),
349 body=typing.cast(
350 typing.Any,
351 parse_obj_as(
352 type_=typing.Any, # type: ignore
353 object_=_response.json(),
354 ),
355 ),
356 )
357 if _response.status_code == 429:
358 raise TooManyRequestsError(
359 headers=dict(_response.headers),
360 body=typing.cast(
361 typing.Any,
362 parse_obj_as(
363 type_=typing.Any, # type: ignore
364 object_=_response.json(),
365 ),
366 ),
367 )
368 _response_json = _response.json()
369 except JSONDecodeError:
370 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
371 except ValidationError as e:
372 raise ParsingError(
373 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
374 )
375 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
376
377 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
378 """
379 Delete a refresh token by its ID.
380
381 Parameters
382 ----------
383 id : str
384 ID of the refresh token to delete.
385
386 request_options : typing.Optional[RequestOptions]
387 Request-specific configuration.
388
389 Returns
390 -------
391 HttpResponse[None]
392 """
393 _response = self._client_wrapper.httpx_client.request(
394 f"refresh-tokens/{encode_path_param(id)}",
395 method="DELETE",
396 request_options=request_options,
397 )
398 try:
399 if 200 <= _response.status_code < 300:
400 return HttpResponse(response=_response, data=None)
401 if _response.status_code == 400:
402 raise BadRequestError(
403 headers=dict(_response.headers),
404 body=typing.cast(
405 typing.Any,
406 parse_obj_as(
407 type_=typing.Any, # type: ignore
408 object_=_response.json(),
409 ),
410 ),
411 )
412 if _response.status_code == 401:
413 raise UnauthorizedError(
414 headers=dict(_response.headers),
415 body=typing.cast(
416 typing.Any,
417 parse_obj_as(
418 type_=typing.Any, # type: ignore
419 object_=_response.json(),
420 ),
421 ),
422 )
423 if _response.status_code == 403:
424 raise ForbiddenError(
425 headers=dict(_response.headers),
426 body=typing.cast(
427 typing.Any,
428 parse_obj_as(
429 type_=typing.Any, # type: ignore
430 object_=_response.json(),
431 ),
432 ),
433 )
434 if _response.status_code == 429:
435 raise TooManyRequestsError(
436 headers=dict(_response.headers),
437 body=typing.cast(
438 typing.Any,
439 parse_obj_as(
440 type_=typing.Any, # type: ignore
441 object_=_response.json(),
442 ),
443 ),
444 )
445 _response_json = _response.json()
446 except JSONDecodeError:
447 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
448 except ValidationError as e:
449 raise ParsingError(
450 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
451 )
452 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
453
454 def update(
455 self,
456 id: str,
457 *,
458 refresh_token_metadata: typing.Optional[RefreshTokenMetadata] = OMIT,
459 request_options: typing.Optional[RequestOptions] = None,
460 ) -> HttpResponse[UpdateRefreshTokenResponseContent]:
461 """
462 Update a refresh token by its ID.
463
464 Parameters
465 ----------
466 id : str
467 ID of the refresh token to update.
468
469 refresh_token_metadata : typing.Optional[RefreshTokenMetadata]
470 Metadata associated with the refresh token. Pass null or {} to remove all metadata.
471
472 request_options : typing.Optional[RequestOptions]
473 Request-specific configuration.
474
475 Returns
476 -------
477 HttpResponse[UpdateRefreshTokenResponseContent]
478 Refresh token successfully updated.
479 """
480 _response = self._client_wrapper.httpx_client.request(
481 f"refresh-tokens/{encode_path_param(id)}",
482 method="PATCH",
483 json={
484 "refresh_token_metadata": refresh_token_metadata,
485 },
486 headers={
487 "content-type": "application/json",
488 },
489 request_options=request_options,
490 omit=OMIT,
491 )
492 try:
493 if 200 <= _response.status_code < 300:
494 _data = typing.cast(
495 UpdateRefreshTokenResponseContent,
496 parse_obj_as(
497 type_=UpdateRefreshTokenResponseContent, # type: ignore
498 object_=_response.json(),
499 ),
500 )
501 return HttpResponse(response=_response, data=_data)
502 if _response.status_code == 400:
503 raise BadRequestError(
504 headers=dict(_response.headers),
505 body=typing.cast(
506 typing.Any,
507 parse_obj_as(
508 type_=typing.Any, # type: ignore
509 object_=_response.json(),
510 ),
511 ),
512 )
513 if _response.status_code == 401:
514 raise UnauthorizedError(
515 headers=dict(_response.headers),
516 body=typing.cast(
517 typing.Any,
518 parse_obj_as(
519 type_=typing.Any, # type: ignore
520 object_=_response.json(),
521 ),
522 ),
523 )
524 if _response.status_code == 403:
525 raise ForbiddenError(
526 headers=dict(_response.headers),
527 body=typing.cast(
528 typing.Any,
529 parse_obj_as(
530 type_=typing.Any, # type: ignore
531 object_=_response.json(),
532 ),
533 ),
534 )
535 if _response.status_code == 404:
536 raise NotFoundError(
537 headers=dict(_response.headers),
538 body=typing.cast(
539 typing.Any,
540 parse_obj_as(
541 type_=typing.Any, # type: ignore
542 object_=_response.json(),
543 ),
544 ),
545 )
546 if _response.status_code == 429:
547 raise TooManyRequestsError(
548 headers=dict(_response.headers),
549 body=typing.cast(
550 typing.Any,
551 parse_obj_as(
552 type_=typing.Any, # type: ignore
553 object_=_response.json(),
554 ),
555 ),
556 )
557 _response_json = _response.json()
558 except JSONDecodeError:
559 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
560 except ValidationError as e:
561 raise ParsingError(
562 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
563 )
564 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
565
566
567 class AsyncRawRefreshTokensClient:
568 def __init__(self, *, client_wrapper: AsyncClientWrapper):
569 self._client_wrapper = client_wrapper
570
571 async def list(
572 self,
573 *,
574 user_id: str,
575 client_id: typing.Optional[str] = None,
576 from_: typing.Optional[str] = None,
577 take: typing.Optional[int] = 50,
578 fields: typing.Optional[str] = None,
579 include_fields: typing.Optional[bool] = None,
580 request_options: typing.Optional[RequestOptions] = None,
581 ) -> AsyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]:
582 """
583 Retrieve a paginated list of refresh tokens for a specific user, with optional filtering by client ID. Results are sorted by credential_id ascending.
584
585 Parameters
586 ----------
587 user_id : str
588 ID of the user whose refresh tokens to retrieve. Required.
589
590 client_id : typing.Optional[str]
591 Filter results by client ID. Only valid when user_id is provided.
592
593 from_ : typing.Optional[str]
594 An opaque cursor from which to start the selection (exclusive). Expires after 24 hours. Obtained from the next property of a previous response.
595
596 take : typing.Optional[int]
597 Number of results per page. Defaults to 50.
598
599 fields : typing.Optional[str]
600 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.
601
602 include_fields : typing.Optional[bool]
603 Whether specified fields are to be included (true) or excluded (false).
604
605 request_options : typing.Optional[RequestOptions]
606 Request-specific configuration.
607
608 Returns
609 -------
610 AsyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]
611 The refresh tokens were retrieved.
612 """
613 _response = await self._client_wrapper.httpx_client.request(
614 "refresh-tokens",
615 method="GET",
616 params={
617 "user_id": user_id,
618 "client_id": client_id,
619 "from": from_,
620 "take": take,
621 "fields": fields,
622 "include_fields": include_fields,
623 },
624 request_options=request_options,
625 )
626 try:
627 if 200 <= _response.status_code < 300:
628 _parsed_response = typing.cast(
629 GetRefreshTokensPaginatedResponseContent,
630 parse_obj_as(
631 type_=GetRefreshTokensPaginatedResponseContent, # type: ignore
632 object_=_response.json(),
633 ),
634 )
635 _items = _parsed_response.refresh_tokens
636 _parsed_next = _parsed_response.next
637 _has_next = _parsed_next is not None and _parsed_next != ""
638
639 async def _get_next():
640 return await self.list(
641 user_id=user_id,
642 client_id=client_id,
643 from_=_parsed_next,
644 take=take,
645 fields=fields,
646 include_fields=include_fields,
647 request_options=request_options,
648 )
649
650 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
651 if _response.status_code == 400:
652 raise BadRequestError(
653 headers=dict(_response.headers),
654 body=typing.cast(
655 typing.Any,
656 parse_obj_as(
657 type_=typing.Any, # type: ignore
658 object_=_response.json(),
659 ),
660 ),
661 )
662 if _response.status_code == 401:
663 raise UnauthorizedError(
664 headers=dict(_response.headers),
665 body=typing.cast(
666 typing.Any,
667 parse_obj_as(
668 type_=typing.Any, # type: ignore
669 object_=_response.json(),
670 ),
671 ),
672 )
673 if _response.status_code == 403:
674 raise ForbiddenError(
675 headers=dict(_response.headers),
676 body=typing.cast(
677 typing.Any,
678 parse_obj_as(
679 type_=typing.Any, # type: ignore
680 object_=_response.json(),
681 ),
682 ),
683 )
684 if _response.status_code == 404:
685 raise NotFoundError(
686 headers=dict(_response.headers),
687 body=typing.cast(
688 typing.Any,
689 parse_obj_as(
690 type_=typing.Any, # type: ignore
691 object_=_response.json(),
692 ),
693 ),
694 )
695 if _response.status_code == 429:
696 raise TooManyRequestsError(
697 headers=dict(_response.headers),
698 body=typing.cast(
699 typing.Any,
700 parse_obj_as(
701 type_=typing.Any, # type: ignore
702 object_=_response.json(),
703 ),
704 ),
705 )
706 _response_json = _response.json()
707 except JSONDecodeError:
708 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
709 except ValidationError as e:
710 raise ParsingError(
711 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
712 )
713 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
714
715 async def revoke(
716 self,
717 *,
718 ids: typing.Optional[typing.Sequence[str]] = OMIT,
719 user_id: typing.Optional[str] = OMIT,
720 client_id: typing.Optional[str] = OMIT,
721 audience: typing.Optional[str] = OMIT,
722 request_options: typing.Optional[RequestOptions] = None,
723 ) -> AsyncHttpResponse[None]:
724 """
725 Revoke refresh tokens in bulk by ID list, user, user+client, or user+client+audience.
726
727 Parameters
728 ----------
729 ids : typing.Optional[typing.Sequence[str]]
730 Array of refresh token IDs to revoke. Limited to 100 at a time.
731
732 user_id : typing.Optional[str]
733 Revoke all refresh tokens for this user.
734
735 client_id : typing.Optional[str]
736 Revoke refresh tokens for this client. Must be paired with `user_id`; optionally narrowed further with `audience`.
737
738 audience : typing.Optional[str]
739 Resource server identifier (audience) to scope the revocation. Must be used with both `user_id` and `client_id`.
740
741 request_options : typing.Optional[RequestOptions]
742 Request-specific configuration.
743
744 Returns
745 -------
746 AsyncHttpResponse[None]
747 """
748 _response = await self._client_wrapper.httpx_client.request(
749 "refresh-tokens/revoke",
750 method="POST",
751 json={
752 "ids": ids,
753 "user_id": user_id,
754 "client_id": client_id,
755 "audience": audience,
756 },
757 headers={
758 "content-type": "application/json",
759 },
760 request_options=request_options,
761 omit=OMIT,
762 )
763 try:
764 if 200 <= _response.status_code < 300:
765 return AsyncHttpResponse(response=_response, data=None)
766 if _response.status_code == 400:
767 raise BadRequestError(
768 headers=dict(_response.headers),
769 body=typing.cast(
770 typing.Any,
771 parse_obj_as(
772 type_=typing.Any, # type: ignore
773 object_=_response.json(),
774 ),
775 ),
776 )
777 if _response.status_code == 401:
778 raise UnauthorizedError(
779 headers=dict(_response.headers),
780 body=typing.cast(
781 typing.Any,
782 parse_obj_as(
783 type_=typing.Any, # type: ignore
784 object_=_response.json(),
785 ),
786 ),
787 )
788 if _response.status_code == 403:
789 raise ForbiddenError(
790 headers=dict(_response.headers),
791 body=typing.cast(
792 typing.Any,
793 parse_obj_as(
794 type_=typing.Any, # type: ignore
795 object_=_response.json(),
796 ),
797 ),
798 )
799 if _response.status_code == 429:
800 raise TooManyRequestsError(
801 headers=dict(_response.headers),
802 body=typing.cast(
803 typing.Any,
804 parse_obj_as(
805 type_=typing.Any, # type: ignore
806 object_=_response.json(),
807 ),
808 ),
809 )
810 _response_json = _response.json()
811 except JSONDecodeError:
812 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
813 except ValidationError as e:
814 raise ParsingError(
815 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
816 )
817 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
818
819 async def get(
820 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
821 ) -> AsyncHttpResponse[GetRefreshTokenResponseContent]:
822 """
823 Retrieve refresh token information.
824
825 Parameters
826 ----------
827 id : str
828 ID refresh token to retrieve
829
830 request_options : typing.Optional[RequestOptions]
831 Request-specific configuration.
832
833 Returns
834 -------
835 AsyncHttpResponse[GetRefreshTokenResponseContent]
836 The refresh token was retrieved
837 """
838 _response = await self._client_wrapper.httpx_client.request(
839 f"refresh-tokens/{encode_path_param(id)}",
840 method="GET",
841 request_options=request_options,
842 )
843 try:
844 if 200 <= _response.status_code < 300:
845 _data = typing.cast(
846 GetRefreshTokenResponseContent,
847 parse_obj_as(
848 type_=GetRefreshTokenResponseContent, # type: ignore
849 object_=_response.json(),
850 ),
851 )
852 return AsyncHttpResponse(response=_response, data=_data)
853 if _response.status_code == 400:
854 raise BadRequestError(
855 headers=dict(_response.headers),
856 body=typing.cast(
857 typing.Any,
858 parse_obj_as(
859 type_=typing.Any, # type: ignore
860 object_=_response.json(),
861 ),
862 ),
863 )
864 if _response.status_code == 401:
865 raise UnauthorizedError(
866 headers=dict(_response.headers),
867 body=typing.cast(
868 typing.Any,
869 parse_obj_as(
870 type_=typing.Any, # type: ignore
871 object_=_response.json(),
872 ),
873 ),
874 )
875 if _response.status_code == 403:
876 raise ForbiddenError(
877 headers=dict(_response.headers),
878 body=typing.cast(
879 typing.Any,
880 parse_obj_as(
881 type_=typing.Any, # type: ignore
882 object_=_response.json(),
883 ),
884 ),
885 )
886 if _response.status_code == 404:
887 raise NotFoundError(
888 headers=dict(_response.headers),
889 body=typing.cast(
890 typing.Any,
891 parse_obj_as(
892 type_=typing.Any, # type: ignore
893 object_=_response.json(),
894 ),
895 ),
896 )
897 if _response.status_code == 429:
898 raise TooManyRequestsError(
899 headers=dict(_response.headers),
900 body=typing.cast(
901 typing.Any,
902 parse_obj_as(
903 type_=typing.Any, # type: ignore
904 object_=_response.json(),
905 ),
906 ),
907 )
908 _response_json = _response.json()
909 except JSONDecodeError:
910 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
911 except ValidationError as e:
912 raise ParsingError(
913 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
914 )
915 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
916
917 async def delete(
918 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
919 ) -> AsyncHttpResponse[None]:
920 """
921 Delete a refresh token by its ID.
922
923 Parameters
924 ----------
925 id : str
926 ID of the refresh token to delete.
927
928 request_options : typing.Optional[RequestOptions]
929 Request-specific configuration.
930
931 Returns
932 -------
933 AsyncHttpResponse[None]
934 """
935 _response = await self._client_wrapper.httpx_client.request(
936 f"refresh-tokens/{encode_path_param(id)}",
937 method="DELETE",
938 request_options=request_options,
939 )
940 try:
941 if 200 <= _response.status_code < 300:
942 return AsyncHttpResponse(response=_response, data=None)
943 if _response.status_code == 400:
944 raise BadRequestError(
945 headers=dict(_response.headers),
946 body=typing.cast(
947 typing.Any,
948 parse_obj_as(
949 type_=typing.Any, # type: ignore
950 object_=_response.json(),
951 ),
952 ),
953 )
954 if _response.status_code == 401:
955 raise UnauthorizedError(
956 headers=dict(_response.headers),
957 body=typing.cast(
958 typing.Any,
959 parse_obj_as(
960 type_=typing.Any, # type: ignore
961 object_=_response.json(),
962 ),
963 ),
964 )
965 if _response.status_code == 403:
966 raise ForbiddenError(
967 headers=dict(_response.headers),
968 body=typing.cast(
969 typing.Any,
970 parse_obj_as(
971 type_=typing.Any, # type: ignore
972 object_=_response.json(),
973 ),
974 ),
975 )
976 if _response.status_code == 429:
977 raise TooManyRequestsError(
978 headers=dict(_response.headers),
979 body=typing.cast(
980 typing.Any,
981 parse_obj_as(
982 type_=typing.Any, # type: ignore
983 object_=_response.json(),
984 ),
985 ),
986 )
987 _response_json = _response.json()
988 except JSONDecodeError:
989 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
990 except ValidationError as e:
991 raise ParsingError(
992 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
993 )
994 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
995
996 async def update(
997 self,
998 id: str,
999 *,
1000 refresh_token_metadata: typing.Optional[RefreshTokenMetadata] = OMIT,
1001 request_options: typing.Optional[RequestOptions] = None,
1002 ) -> AsyncHttpResponse[UpdateRefreshTokenResponseContent]:
1003 """
1004 Update a refresh token by its ID.
1005
1006 Parameters
1007 ----------
1008 id : str
1009 ID of the refresh token to update.
1010
1011 refresh_token_metadata : typing.Optional[RefreshTokenMetadata]
1012 Metadata associated with the refresh token. Pass null or {} to remove all metadata.
1013
1014 request_options : typing.Optional[RequestOptions]
1015 Request-specific configuration.
1016
1017 Returns
1018 -------
1019 AsyncHttpResponse[UpdateRefreshTokenResponseContent]
1020 Refresh token successfully updated.
1021 """
1022 _response = await self._client_wrapper.httpx_client.request(
1023 f"refresh-tokens/{encode_path_param(id)}",
1024 method="PATCH",
1025 json={
1026 "refresh_token_metadata": refresh_token_metadata,
1027 },
1028 headers={
1029 "content-type": "application/json",
1030 },
1031 request_options=request_options,
1032 omit=OMIT,
1033 )
1034 try:
1035 if 200 <= _response.status_code < 300:
1036 _data = typing.cast(
1037 UpdateRefreshTokenResponseContent,
1038 parse_obj_as(
1039 type_=UpdateRefreshTokenResponseContent, # type: ignore
1040 object_=_response.json(),
1041 ),
1042 )
1043 return AsyncHttpResponse(response=_response, data=_data)
1044 if _response.status_code == 400:
1045 raise BadRequestError(
1046 headers=dict(_response.headers),
1047 body=typing.cast(
1048 typing.Any,
1049 parse_obj_as(
1050 type_=typing.Any, # type: ignore
1051 object_=_response.json(),
1052 ),
1053 ),
1054 )
1055 if _response.status_code == 401:
1056 raise UnauthorizedError(
1057 headers=dict(_response.headers),
1058 body=typing.cast(
1059 typing.Any,
1060 parse_obj_as(
1061 type_=typing.Any, # type: ignore
1062 object_=_response.json(),
1063 ),
1064 ),
1065 )
1066 if _response.status_code == 403:
1067 raise ForbiddenError(
1068 headers=dict(_response.headers),
1069 body=typing.cast(
1070 typing.Any,
1071 parse_obj_as(
1072 type_=typing.Any, # type: ignore
1073 object_=_response.json(),
1074 ),
1075 ),
1076 )
1077 if _response.status_code == 404:
1078 raise NotFoundError(
1079 headers=dict(_response.headers),
1080 body=typing.cast(
1081 typing.Any,
1082 parse_obj_as(
1083 type_=typing.Any, # type: ignore
1084 object_=_response.json(),
1085 ),
1086 ),
1087 )
1088 if _response.status_code == 429:
1089 raise TooManyRequestsError(
1090 headers=dict(_response.headers),
1091 body=typing.cast(
1092 typing.Any,
1093 parse_obj_as(
1094 type_=typing.Any, # type: ignore
1095 object_=_response.json(),
1096 ),
1097 ),
1098 )
1099 _response_json = _response.json()
1100 except JSONDecodeError:
1101 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1102 except ValidationError as e:
1103 raise ParsingError(
1104 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1105 )
1106 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)