|
10 | 10 | from ..types.api_token_response import ApiTokenResponse
|
11 | 11 | from ..types.access_token_response import AccessTokenResponse
|
12 | 12 | from ..errors.unauthorized_error import UnauthorizedError
|
| 13 | +from ..types.rotate_token_response import RotateTokenResponse |
| 14 | +from ..errors.bad_request_error import BadRequestError |
13 | 15 | from ..core.client_wrapper import AsyncClientWrapper
|
14 | 16 |
|
15 | 17 | # this is used as the default value for optional parameters
|
@@ -225,6 +227,70 @@ def refresh(self, *, refresh: str, request_options: typing.Optional[RequestOptio
|
225 | 227 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
226 | 228 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
227 | 229 |
|
| 230 | + def rotate(self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None) -> RotateTokenResponse: |
| 231 | + """ |
| 232 | + Blacklist existing refresh token, and get a new refresh token. |
| 233 | +
|
| 234 | + Parameters |
| 235 | + ---------- |
| 236 | + refresh : str |
| 237 | + JWT refresh token |
| 238 | +
|
| 239 | + request_options : typing.Optional[RequestOptions] |
| 240 | + Request-specific configuration. |
| 241 | +
|
| 242 | + Returns |
| 243 | + ------- |
| 244 | + RotateTokenResponse |
| 245 | + Refresh token successfully rotated |
| 246 | +
|
| 247 | + Examples |
| 248 | + -------- |
| 249 | + from label_studio_sdk import LabelStudio |
| 250 | +
|
| 251 | + client = LabelStudio( |
| 252 | + api_key="YOUR_API_KEY", |
| 253 | + ) |
| 254 | + client.tokens.rotate( |
| 255 | + refresh="refresh", |
| 256 | + ) |
| 257 | + """ |
| 258 | + _response = self._client_wrapper.httpx_client.request( |
| 259 | + "api/token/rotate", |
| 260 | + method="POST", |
| 261 | + json={ |
| 262 | + "refresh": refresh, |
| 263 | + }, |
| 264 | + headers={ |
| 265 | + "content-type": "application/json", |
| 266 | + }, |
| 267 | + request_options=request_options, |
| 268 | + omit=OMIT, |
| 269 | + ) |
| 270 | + try: |
| 271 | + if 200 <= _response.status_code < 300: |
| 272 | + return typing.cast( |
| 273 | + RotateTokenResponse, |
| 274 | + parse_obj_as( |
| 275 | + type_=RotateTokenResponse, # type: ignore |
| 276 | + object_=_response.json(), |
| 277 | + ), |
| 278 | + ) |
| 279 | + if _response.status_code == 400: |
| 280 | + raise BadRequestError( |
| 281 | + typing.cast( |
| 282 | + typing.Optional[typing.Any], |
| 283 | + parse_obj_as( |
| 284 | + type_=typing.Optional[typing.Any], # type: ignore |
| 285 | + object_=_response.json(), |
| 286 | + ), |
| 287 | + ) |
| 288 | + ) |
| 289 | + _response_json = _response.json() |
| 290 | + except JSONDecodeError: |
| 291 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 292 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 293 | + |
228 | 294 |
|
229 | 295 | class AsyncTokensClient:
|
230 | 296 | def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
@@ -468,3 +534,77 @@ async def main() -> None:
|
468 | 534 | except JSONDecodeError:
|
469 | 535 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
470 | 536 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
| 537 | + |
| 538 | + async def rotate( |
| 539 | + self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None |
| 540 | + ) -> RotateTokenResponse: |
| 541 | + """ |
| 542 | + Blacklist existing refresh token, and get a new refresh token. |
| 543 | +
|
| 544 | + Parameters |
| 545 | + ---------- |
| 546 | + refresh : str |
| 547 | + JWT refresh token |
| 548 | +
|
| 549 | + request_options : typing.Optional[RequestOptions] |
| 550 | + Request-specific configuration. |
| 551 | +
|
| 552 | + Returns |
| 553 | + ------- |
| 554 | + RotateTokenResponse |
| 555 | + Refresh token successfully rotated |
| 556 | +
|
| 557 | + Examples |
| 558 | + -------- |
| 559 | + import asyncio |
| 560 | +
|
| 561 | + from label_studio_sdk import AsyncLabelStudio |
| 562 | +
|
| 563 | + client = AsyncLabelStudio( |
| 564 | + api_key="YOUR_API_KEY", |
| 565 | + ) |
| 566 | +
|
| 567 | +
|
| 568 | + async def main() -> None: |
| 569 | + await client.tokens.rotate( |
| 570 | + refresh="refresh", |
| 571 | + ) |
| 572 | +
|
| 573 | +
|
| 574 | + asyncio.run(main()) |
| 575 | + """ |
| 576 | + _response = await self._client_wrapper.httpx_client.request( |
| 577 | + "api/token/rotate", |
| 578 | + method="POST", |
| 579 | + json={ |
| 580 | + "refresh": refresh, |
| 581 | + }, |
| 582 | + headers={ |
| 583 | + "content-type": "application/json", |
| 584 | + }, |
| 585 | + request_options=request_options, |
| 586 | + omit=OMIT, |
| 587 | + ) |
| 588 | + try: |
| 589 | + if 200 <= _response.status_code < 300: |
| 590 | + return typing.cast( |
| 591 | + RotateTokenResponse, |
| 592 | + parse_obj_as( |
| 593 | + type_=RotateTokenResponse, # type: ignore |
| 594 | + object_=_response.json(), |
| 595 | + ), |
| 596 | + ) |
| 597 | + if _response.status_code == 400: |
| 598 | + raise BadRequestError( |
| 599 | + typing.cast( |
| 600 | + typing.Optional[typing.Any], |
| 601 | + parse_obj_as( |
| 602 | + type_=typing.Optional[typing.Any], # type: ignore |
| 603 | + object_=_response.json(), |
| 604 | + ), |
| 605 | + ) |
| 606 | + ) |
| 607 | + _response_json = _response.json() |
| 608 | + except JSONDecodeError: |
| 609 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 610 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments