Skip to content

Commit e97cb4f

Browse files
committed
feat: support new qat_ SSO tokens.
* Support QUADS 3.x qat_ SSO permanent tokens.
1 parent b4f8e31 commit e97cb4f

5 files changed

Lines changed: 24 additions & 5 deletions

File tree

rpm/quads-lib.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
%define name quads-lib
1313
%define reponame python-quads-lib
1414
%define branch development
15-
%define version 0.1.12
15+
%define version 0.1.13
1616
%define build_timestamp %{lua: print(os.date("%Y%m%d"))}
1717

1818
Summary: Python client library for interacting with the QUADS API

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def read(*names, **kwargs):
1313

1414
setup(
1515
name="quads-lib",
16-
version="0.1.12",
16+
version="0.1.13",
1717
license="LGPL-3.0-only",
1818
description="Python client library for interacting with the QUADS API",
1919
long_description="{}\n{}".format(

src/quads_lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.12"
1+
__version__ = "0.1.13"
22

33
from .quads import QuadsApi
44

src/quads_lib/base.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(
2323
password: str,
2424
base_url: str,
2525
verify: Union[bool, str] = False,
26+
api_token: Optional[str] = None,
2627
):
2728
"""
2829
Initialize QuadsBase.
@@ -36,6 +37,8 @@ def __init__(
3637
backward compatibility)
3738
- True: Enable verification using default CA bundle
3839
- str: Path to a custom CA bundle file
40+
api_token: Pre-generated API token (qat_-prefixed) for direct
41+
bearer auth without username/password login.
3942
"""
4043
self.username = username
4144
self.password = password
@@ -44,10 +47,16 @@ def __init__(
4447
self.session = Session()
4548
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])
4649
self.session.mount("http://", HTTPAdapter(max_retries=retries))
47-
self.auth = HTTPBasicAuth(self.username, self.password)
48-
self.token = None
4950
self.headers = {}
5051

52+
if api_token:
53+
self.token = api_token
54+
self.session.headers.update({"Authorization": f"Bearer {api_token}"})
55+
self.auth = None
56+
else:
57+
self.auth = HTTPBasicAuth(self.username, self.password)
58+
self.token = None
59+
5160
def __enter__(self):
5261
self.login()
5362
return self

src/quads_lib/quads.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ def register(self) -> dict:
2222
return json_response
2323

2424
def login(self) -> dict:
25+
if self.token and self.token.startswith("qat_"):
26+
return {
27+
"status_code": 201,
28+
"status": "success",
29+
"message": "Authenticated via API token",
30+
"auth_token": self.token,
31+
}
2532
endpoint = urljoin(self.base_url, "login")
2633
_response = self.session.post(endpoint, auth=self.auth, verify=self.verify)
2734
json_response = _response.json()
@@ -30,6 +37,9 @@ def login(self) -> dict:
3037
self.session.headers.update({"Authorization": f"Bearer {self.token}"})
3138
return json_response
3239

40+
def get_current_user(self) -> dict:
41+
return self.get("me")
42+
3343
def logout(self) -> dict:
3444
json_response = self._make_request("POST", "logout")
3545
if json_response.get("status_code") == 200:

0 commit comments

Comments
 (0)