indoxrouter 0.1.11__py3-none-any.whl → 0.1.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- indoxrouter/client.py +41 -15
- {indoxrouter-0.1.11.dist-info → indoxrouter-0.1.12.dist-info}/METADATA +1 -1
- {indoxrouter-0.1.11.dist-info → indoxrouter-0.1.12.dist-info}/RECORD +5 -5
- {indoxrouter-0.1.11.dist-info → indoxrouter-0.1.12.dist-info}/WHEEL +0 -0
- {indoxrouter-0.1.11.dist-info → indoxrouter-0.1.12.dist-info}/top_level.txt +0 -0
indoxrouter/client.py
CHANGED
@@ -120,31 +120,38 @@ class Client:
|
|
120
120
|
This uses the /auth/token endpoint to get JWT tokens using the API key.
|
121
121
|
"""
|
122
122
|
try:
|
123
|
-
# First try
|
124
|
-
logger.debug("Authenticating with API key
|
123
|
+
# First try with the dedicated API key endpoint
|
124
|
+
logger.debug("Authenticating with dedicated API key endpoint")
|
125
125
|
response = self.session.post(
|
126
|
-
f"{self.base_url}/api/v1/auth/
|
127
|
-
|
128
|
-
"username": self.api_key,
|
129
|
-
"password": "",
|
130
|
-
},
|
126
|
+
f"{self.base_url}/api/v1/auth/api-key",
|
127
|
+
headers={"X-API-Key": self.api_key},
|
131
128
|
timeout=self.timeout,
|
132
129
|
)
|
133
130
|
|
134
131
|
if response.status_code != 200:
|
135
|
-
#
|
136
|
-
logger.debug(
|
137
|
-
"First auth method failed, trying with API key as password"
|
138
|
-
)
|
132
|
+
# If dedicated endpoint fails, try using the API key as a username
|
133
|
+
logger.debug("API key endpoint failed, trying with API key as username")
|
139
134
|
response = self.session.post(
|
140
|
-
f"{self.base_url}/api/v1/auth/
|
141
|
-
|
142
|
-
"username":
|
143
|
-
"password": self.api_key,
|
135
|
+
f"{self.base_url}/api/v1/auth/token",
|
136
|
+
data={
|
137
|
+
"username": self.api_key,
|
138
|
+
"password": self.api_key, # Try using API key as both username and password
|
144
139
|
},
|
145
140
|
timeout=self.timeout,
|
146
141
|
)
|
147
142
|
|
143
|
+
if response.status_code != 200:
|
144
|
+
# Try one more method - the token endpoint with different format
|
145
|
+
logger.debug("Trying with API key as token parameter")
|
146
|
+
response = self.session.post(
|
147
|
+
f"{self.base_url}/api/v1/auth/token",
|
148
|
+
data={
|
149
|
+
"username": "pip_client",
|
150
|
+
"password": self.api_key,
|
151
|
+
},
|
152
|
+
timeout=self.timeout,
|
153
|
+
)
|
154
|
+
|
148
155
|
if response.status_code != 200:
|
149
156
|
error_data = {}
|
150
157
|
try:
|
@@ -156,6 +163,17 @@ class Client:
|
|
156
163
|
f"Authentication failed: {error_data.get('detail', 'Unknown error')}"
|
157
164
|
)
|
158
165
|
|
166
|
+
# Check if we have a token in the response body
|
167
|
+
try:
|
168
|
+
response_data = response.json()
|
169
|
+
if "access_token" in response_data:
|
170
|
+
# Store token in the session object for later use
|
171
|
+
self.access_token = response_data["access_token"]
|
172
|
+
logger.debug("Retrieved access token from response body")
|
173
|
+
except:
|
174
|
+
# If we couldn't parse JSON, that's fine - we'll rely on cookies
|
175
|
+
logger.debug("No token found in response body, will rely on cookies")
|
176
|
+
|
159
177
|
# At this point, the cookies should be set in the session
|
160
178
|
logger.debug("Authentication successful")
|
161
179
|
|
@@ -227,6 +245,10 @@ class Client:
|
|
227
245
|
url = f"{self.base_url}/{endpoint}"
|
228
246
|
headers = {"Content-Type": "application/json"}
|
229
247
|
|
248
|
+
# Add Authorization header if we have an access token
|
249
|
+
if hasattr(self, "access_token") and self.access_token:
|
250
|
+
headers["Authorization"] = f"Bearer {self.access_token}"
|
251
|
+
|
230
252
|
# logger.debug(f"Making {method} request to {url}")
|
231
253
|
# if data:
|
232
254
|
# logger.debug(f"Request data: {json.dumps(data, indent=2)}")
|
@@ -257,6 +279,10 @@ class Client:
|
|
257
279
|
logger.debug("Received 401, attempting to reauthenticate")
|
258
280
|
self._authenticate()
|
259
281
|
|
282
|
+
# Update Authorization header with new token if available
|
283
|
+
if hasattr(self, "access_token") and self.access_token:
|
284
|
+
headers["Authorization"] = f"Bearer {self.access_token}"
|
285
|
+
|
260
286
|
# Retry the request after reauthentication
|
261
287
|
response = self.session.request(
|
262
288
|
method,
|
@@ -1,9 +1,9 @@
|
|
1
1
|
indoxrouter/__init__.py,sha256=28pdx482uGFF_S1msov0LTTGsFTvVBKRqMkDmoXWUBY,1416
|
2
|
-
indoxrouter/client.py,sha256=
|
2
|
+
indoxrouter/client.py,sha256=ixzCJP28ddYFQxwRiqdY5Fp1CB978DJpI4yCiOI3s4o,28898
|
3
3
|
indoxrouter/constants.py,sha256=D-l5qhEmeDIXOEfogvf6lJI1Sw_fXSKZy-Nj_l_MV7E,1184
|
4
4
|
indoxrouter/exceptions.py,sha256=0ULxtK9va4718PGTO5VoClXYEJeojpiM-7AganeiZZ4,1263
|
5
5
|
indoxrouter/test_api_key.py,sha256=u4fUTJwxC7-kTrLdCq8u5a1Mx66jeExfsBlHLhyzNmA,3229
|
6
|
-
indoxrouter-0.1.
|
7
|
-
indoxrouter-0.1.
|
8
|
-
indoxrouter-0.1.
|
9
|
-
indoxrouter-0.1.
|
6
|
+
indoxrouter-0.1.12.dist-info/METADATA,sha256=pRupY-6V6GrozkXidKGm_qf6fBY2clAqYwgKAU5OJww,6004
|
7
|
+
indoxrouter-0.1.12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
8
|
+
indoxrouter-0.1.12.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
|
9
|
+
indoxrouter-0.1.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|