From e97cb4f52b274824571e2478ebe13c9f160e8617 Mon Sep 17 00:00:00 2001 From: Will Foster Date: Mon, 25 May 2026 13:58:37 +0100 Subject: [PATCH] feat: support new qat_ SSO tokens. * Support QUADS 3.x qat_ SSO permanent tokens. --- rpm/quads-lib.spec | 2 +- setup.py | 2 +- src/quads_lib/__init__.py | 2 +- src/quads_lib/base.py | 13 +++++++++++-- src/quads_lib/quads.py | 10 ++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/rpm/quads-lib.spec b/rpm/quads-lib.spec index db44cf2..f9886ca 100644 --- a/rpm/quads-lib.spec +++ b/rpm/quads-lib.spec @@ -12,7 +12,7 @@ %define name quads-lib %define reponame python-quads-lib %define branch development -%define version 0.1.12 +%define version 0.1.13 %define build_timestamp %{lua: print(os.date("%Y%m%d"))} Summary: Python client library for interacting with the QUADS API diff --git a/setup.py b/setup.py index c815511..64f320a 100755 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def read(*names, **kwargs): setup( name="quads-lib", - version="0.1.12", + version="0.1.13", license="LGPL-3.0-only", description="Python client library for interacting with the QUADS API", long_description="{}\n{}".format( diff --git a/src/quads_lib/__init__.py b/src/quads_lib/__init__.py index 2aee39d..7ba8667 100644 --- a/src/quads_lib/__init__.py +++ b/src/quads_lib/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.12" +__version__ = "0.1.13" from .quads import QuadsApi diff --git a/src/quads_lib/base.py b/src/quads_lib/base.py index 06a5ea6..12f1709 100644 --- a/src/quads_lib/base.py +++ b/src/quads_lib/base.py @@ -23,6 +23,7 @@ def __init__( password: str, base_url: str, verify: Union[bool, str] = False, + api_token: Optional[str] = None, ): """ Initialize QuadsBase. @@ -36,6 +37,8 @@ def __init__( backward compatibility) - True: Enable verification using default CA bundle - str: Path to a custom CA bundle file + api_token: Pre-generated API token (qat_-prefixed) for direct + bearer auth without username/password login. """ self.username = username self.password = password @@ -44,10 +47,16 @@ def __init__( self.session = Session() retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504]) self.session.mount("http://", HTTPAdapter(max_retries=retries)) - self.auth = HTTPBasicAuth(self.username, self.password) - self.token = None self.headers = {} + if api_token: + self.token = api_token + self.session.headers.update({"Authorization": f"Bearer {api_token}"}) + self.auth = None + else: + self.auth = HTTPBasicAuth(self.username, self.password) + self.token = None + def __enter__(self): self.login() return self diff --git a/src/quads_lib/quads.py b/src/quads_lib/quads.py index 986d5c8..e7d00a8 100644 --- a/src/quads_lib/quads.py +++ b/src/quads_lib/quads.py @@ -22,6 +22,13 @@ def register(self) -> dict: return json_response def login(self) -> dict: + if self.token and self.token.startswith("qat_"): + return { + "status_code": 201, + "status": "success", + "message": "Authenticated via API token", + "auth_token": self.token, + } endpoint = urljoin(self.base_url, "login") _response = self.session.post(endpoint, auth=self.auth, verify=self.verify) json_response = _response.json() @@ -30,6 +37,9 @@ def login(self) -> dict: self.session.headers.update({"Authorization": f"Bearer {self.token}"}) return json_response + def get_current_user(self) -> dict: + return self.get("me") + def logout(self) -> dict: json_response = self._make_request("POST", "logout") if json_response.get("status_code") == 200: