pypomes-jwt 0.9.9__tar.gz → 1.0.0__tar.gz
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.
Potentially problematic release.
This version of pypomes-jwt might be problematic. Click here for more details.
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/PKG-INFO +1 -1
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/pyproject.toml +1 -1
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/src/pypomes_jwt/jwt_pomes.py +35 -14
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/.gitignore +0 -0
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/LICENSE +0 -0
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/README.md +0 -0
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/src/pypomes_jwt/__init__.py +0 -0
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/src/pypomes_jwt/jwt_constants.py +0 -0
- {pypomes_jwt-0.9.9 → pypomes_jwt-1.0.0}/src/pypomes_jwt/jwt_registry.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_jwt
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: A collection of Python pomes, penyeach (JWT module)
|
|
5
5
|
Project-URL: Homepage, https://github.com/TheWiseCoder/PyPomes-JWT
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/TheWiseCoder/PyPomes-JWT/issues
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import jwt
|
|
2
|
+
import sys
|
|
2
3
|
from base64 import urlsafe_b64decode
|
|
3
4
|
from flask import Request, Response, request
|
|
4
5
|
from logging import Logger
|
|
6
|
+
from pypomes_core import exc_format
|
|
5
7
|
from pypomes_db import db_select, db_delete
|
|
6
8
|
from typing import Any
|
|
7
9
|
|
|
@@ -152,6 +154,8 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
152
154
|
If the *kid* claim contains such an id, then the cryptographic key needed for validation
|
|
153
155
|
will be obtained from the token database. Otherwise, the current decoding key is used.
|
|
154
156
|
|
|
157
|
+
On success, return the token's claims (header and payload), as documented in *jwt_get_claims()*
|
|
158
|
+
|
|
155
159
|
:param errors: incidental error messages
|
|
156
160
|
:param token: the token to be validated
|
|
157
161
|
:param nature: prefix identifying the nature of locally issued tokens
|
|
@@ -171,7 +175,11 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
171
175
|
try:
|
|
172
176
|
token_header: dict[str, Any] = jwt.get_unverified_header(jwt=token)
|
|
173
177
|
except Exception as e:
|
|
174
|
-
|
|
178
|
+
exc_err: str = exc_format(exc=e,
|
|
179
|
+
exc_info=sys.exc_info())
|
|
180
|
+
if logger:
|
|
181
|
+
logger.error(msg=f"Error retrieving the token's header: {exc_err}")
|
|
182
|
+
op_errors.append(exc_err)
|
|
175
183
|
|
|
176
184
|
if not op_errors:
|
|
177
185
|
token_kid: str = token_header.get("kid")
|
|
@@ -195,7 +203,12 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
195
203
|
if recs:
|
|
196
204
|
token_alg = recs[0][0]
|
|
197
205
|
token_decoder = urlsafe_b64decode(recs[0][1])
|
|
206
|
+
elif op_errors:
|
|
207
|
+
if logger:
|
|
208
|
+
logger.error(msg=f"Error retrieving the token's decoder: {'; '.join(op_errors)}")
|
|
198
209
|
else:
|
|
210
|
+
if logger:
|
|
211
|
+
logger.error(msg="Token not in the database")
|
|
199
212
|
op_errors.append("Invalid token")
|
|
200
213
|
else:
|
|
201
214
|
token_alg = JWT_DEFAULT_ALGORITHM
|
|
@@ -230,12 +243,13 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
230
243
|
"payload": payload
|
|
231
244
|
}
|
|
232
245
|
except Exception as e:
|
|
233
|
-
|
|
246
|
+
exc_err: str = exc_format(exc=e,
|
|
247
|
+
exc_info=sys.exc_info())
|
|
248
|
+
if logger:
|
|
249
|
+
logger.error(msg=f"Error decoding the token: {exc_err}")
|
|
250
|
+
op_errors.append(exc_err)
|
|
234
251
|
|
|
235
252
|
if op_errors:
|
|
236
|
-
err_msg: str = "; ".join(op_errors)
|
|
237
|
-
if logger:
|
|
238
|
-
logger.error(msg=err_msg)
|
|
239
253
|
if isinstance(errors, list):
|
|
240
254
|
errors.extend(op_errors)
|
|
241
255
|
elif logger:
|
|
@@ -335,13 +349,14 @@ def jwt_issue_token(errors: list[str] | None,
|
|
|
335
349
|
logger.debug(msg=f"Token is '{result}'")
|
|
336
350
|
except Exception as e:
|
|
337
351
|
# token issuing failed
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if op_errors:
|
|
352
|
+
exc_err: str = exc_format(exc=e,
|
|
353
|
+
exc_info=sys.exc_info())
|
|
341
354
|
if logger:
|
|
342
|
-
logger.error("
|
|
343
|
-
|
|
344
|
-
|
|
355
|
+
logger.error(msg=f"Error issuing the token: {exc_err}")
|
|
356
|
+
op_errors.append(exc_err)
|
|
357
|
+
|
|
358
|
+
if op_errors and isinstance(errors, list):
|
|
359
|
+
errors.extend(op_errors)
|
|
345
360
|
|
|
346
361
|
return result
|
|
347
362
|
|
|
@@ -385,7 +400,11 @@ def jwt_issue_tokens(errors: list[str] | None,
|
|
|
385
400
|
logger.debug(msg=f"Token data is '{result}'")
|
|
386
401
|
except Exception as e:
|
|
387
402
|
# token issuing failed
|
|
388
|
-
|
|
403
|
+
exc_err: str = exc_format(exc=e,
|
|
404
|
+
exc_info=sys.exc_info())
|
|
405
|
+
if logger:
|
|
406
|
+
logger.error(msg=f"Error issuing the token pair: {exc_err}")
|
|
407
|
+
op_errors.append(exc_err)
|
|
389
408
|
|
|
390
409
|
if op_errors:
|
|
391
410
|
if logger:
|
|
@@ -512,9 +531,11 @@ def jwt_get_claims(errors: list[str] | None,
|
|
|
512
531
|
"payload": payload
|
|
513
532
|
}
|
|
514
533
|
except Exception as e:
|
|
534
|
+
exc_err: str = exc_format(exc=e,
|
|
535
|
+
exc_info=sys.exc_info())
|
|
515
536
|
if logger:
|
|
516
|
-
logger.error(msg=
|
|
537
|
+
logger.error(msg=f"Error retrieving the token's claimsn: {exc_err}")
|
|
517
538
|
if isinstance(errors, list):
|
|
518
|
-
errors.append(
|
|
539
|
+
errors.append(exc_err)
|
|
519
540
|
|
|
520
541
|
return result
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|