From 1ea8bb11c3728d61b8b9a33a162dc8365f8c7601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=D0=98=D1=81=D1=85=D0=B0=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Wed, 3 Dec 2025 01:51:26 +0500 Subject: [PATCH] feat: command for fast refreshing token --- cli/commands/__init__.py | 6 ++++-- cli/commands/refresh_command.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 cli/commands/refresh_command.py diff --git a/cli/commands/__init__.py b/cli/commands/__init__.py index a0c5297..51f7a01 100644 --- a/cli/commands/__init__.py +++ b/cli/commands/__init__.py @@ -1,6 +1,7 @@ -from .exec_command import ExecuteCommandStrategy from .api_command import ApiCallStrategy +from .exec_command import ExecuteCommandStrategy from .get_command import GetCommandStrategy +from .refresh_command import RefreshCommandStrategy from .update_command import UpdateCommandStrategy # Create a mapping of command names to strategy classes @@ -8,5 +9,6 @@ "exec": ExecuteCommandStrategy, "api": ApiCallStrategy, "get": GetCommandStrategy, - "update": UpdateCommandStrategy + "update": UpdateCommandStrategy, + "refresh": RefreshCommandStrategy, } diff --git a/cli/commands/refresh_command.py b/cli/commands/refresh_command.py new file mode 100644 index 0000000..8ce87f2 --- /dev/null +++ b/cli/commands/refresh_command.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import json + +from .api_command import ApiCallStrategy +from .base import PassworkCommand + + +class RefreshCommandStrategy(ApiCallStrategy): + """Refresh the access token using the configured refresh token.""" + + def execute(self, client, args): + args.endpoint = "v1/sessions/refresh" + args.params = json.dumps({"refreshToken": client.refresh_token}) + args.method = "POST" + args.field = None + return super().execute(client, args) + + @staticmethod + def add_command(subparsers): + params = PassworkCommand.base_params() + + parser = subparsers.add_parser( + "refresh", help="Refresh access token using the refresh token" + ) + for key, value in params.items(): + parser.add_argument(key, **value)