pypomes-jwt 1.0.1__tar.gz → 1.0.2__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-1.0.1 → pypomes_jwt-1.0.2}/PKG-INFO +1 -1
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/pyproject.toml +1 -1
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/src/pypomes_jwt/jwt_pomes.py +5 -5
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/src/pypomes_jwt/jwt_registry.py +18 -12
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/.gitignore +0 -0
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/LICENSE +0 -0
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/README.md +0 -0
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/src/pypomes_jwt/__init__.py +0 -0
- {pypomes_jwt-1.0.1 → pypomes_jwt-1.0.2}/src/pypomes_jwt/jwt_constants.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_jwt
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
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
|
|
@@ -436,11 +436,11 @@ def jwt_refresh_tokens(errors: list[str] | None,
|
|
|
436
436
|
# assert the refresh token
|
|
437
437
|
if refresh_token:
|
|
438
438
|
# is the refresh token valid ?
|
|
439
|
-
account_claims = jwt_validate_token(errors=op_errors,
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
439
|
+
account_claims = (jwt_validate_token(errors=op_errors,
|
|
440
|
+
token=refresh_token,
|
|
441
|
+
nature="R",
|
|
442
|
+
account_id=account_id,
|
|
443
|
+
logger=logger) or {}).get("payload")
|
|
444
444
|
# if it is, revoke current refresh token
|
|
445
445
|
if account_claims and jwt_revoke_token(errors=op_errors,
|
|
446
446
|
account_id=account_id,
|
|
@@ -5,7 +5,9 @@ from base64 import urlsafe_b64encode
|
|
|
5
5
|
from datetime import datetime, timezone
|
|
6
6
|
from logging import Logger
|
|
7
7
|
from pypomes_core import str_random
|
|
8
|
-
from pypomes_db import
|
|
8
|
+
from pypomes_db import (
|
|
9
|
+
db_connect, db_commit, db_select, db_insert, db_update, db_delete
|
|
10
|
+
)
|
|
9
11
|
from threading import Lock
|
|
10
12
|
from typing import Any
|
|
11
13
|
|
|
@@ -275,12 +277,11 @@ class JwtRegistry:
|
|
|
275
277
|
key=JWT_ENCODING_KEY,
|
|
276
278
|
algorithm=JWT_DEFAULT_ALGORITHM,
|
|
277
279
|
headers={"kid": "R0"})
|
|
278
|
-
# obtain a DB connection
|
|
280
|
+
# obtain a DB connection
|
|
279
281
|
db_conn: Any = db_connect(errors=errors,
|
|
280
282
|
logger=logger)
|
|
281
283
|
# persist the candidate token (may raise an exception)
|
|
282
|
-
token_id: int = _jwt_persist_token(
|
|
283
|
-
account_id=account_id,
|
|
284
|
+
token_id: int = _jwt_persist_token(account_id=account_id,
|
|
284
285
|
jwt_token=refresh_token,
|
|
285
286
|
db_conn=db_conn,
|
|
286
287
|
logger=logger)
|
|
@@ -297,9 +298,10 @@ class JwtRegistry:
|
|
|
297
298
|
connection=db_conn,
|
|
298
299
|
logger=logger)
|
|
299
300
|
# commit the transaction
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
if not errors:
|
|
302
|
+
db_commit(errors=errors,
|
|
303
|
+
connection=db_conn,
|
|
304
|
+
logger=logger)
|
|
303
305
|
if errors:
|
|
304
306
|
raise RuntimeError("; ".join(errors))
|
|
305
307
|
|
|
@@ -339,8 +341,7 @@ class JwtRegistry:
|
|
|
339
341
|
return result
|
|
340
342
|
|
|
341
343
|
|
|
342
|
-
def _jwt_persist_token(
|
|
343
|
-
account_id: str,
|
|
344
|
+
def _jwt_persist_token(account_id: str,
|
|
344
345
|
jwt_token: str,
|
|
345
346
|
db_conn: Any = None,
|
|
346
347
|
logger: Logger = None) -> int:
|
|
@@ -354,7 +355,6 @@ def _jwt_persist_token(errors: list[str],
|
|
|
354
355
|
|
|
355
356
|
If *db_conn* is provided, then all DB operations will be carried out in the scope of a single transaction.
|
|
356
357
|
|
|
357
|
-
:param errors: incidental errors
|
|
358
358
|
:param account_id: the account identification
|
|
359
359
|
:param jwt_token: the JWT token to persist
|
|
360
360
|
:param db_conn: the database connection to use
|
|
@@ -362,17 +362,19 @@ def _jwt_persist_token(errors: list[str],
|
|
|
362
362
|
:return: the storage id of the inserted token
|
|
363
363
|
:raises RuntimeError: error accessing the token database
|
|
364
364
|
"""
|
|
365
|
-
from pypomes_db import db_select, db_insert, db_delete
|
|
366
365
|
from .jwt_pomes import jwt_get_claims
|
|
367
366
|
|
|
368
367
|
# retrieve the account's tokens
|
|
368
|
+
errors: list[str] = []
|
|
369
369
|
# noinspection PyTypeChecker
|
|
370
370
|
recs: list[tuple[int, str, str, str]] = \
|
|
371
371
|
db_select(errors=errors,
|
|
372
372
|
sel_stmt=f"SELECT {JWT_DB_COL_KID}, {JWT_DB_COL_TOKEN} "
|
|
373
373
|
f"FROM {JWT_DB_TABLE}",
|
|
374
374
|
where_data={JWT_DB_COL_ACCOUNT: account_id},
|
|
375
|
-
connection=db_conn
|
|
375
|
+
connection=db_conn,
|
|
376
|
+
committable=False,
|
|
377
|
+
logger=logger)
|
|
376
378
|
if errors:
|
|
377
379
|
raise RuntimeError("; ".join(errors))
|
|
378
380
|
|
|
@@ -409,6 +411,7 @@ def _jwt_persist_token(errors: list[str],
|
|
|
409
411
|
delete_stmt=f"DELETE FROM {JWT_DB_TABLE}",
|
|
410
412
|
where_data={JWT_DB_COL_KID: expired},
|
|
411
413
|
connection=db_conn,
|
|
414
|
+
committable=False,
|
|
412
415
|
logger=logger)
|
|
413
416
|
if errors:
|
|
414
417
|
raise RuntimeError("; ".join(errors))
|
|
@@ -422,6 +425,7 @@ def _jwt_persist_token(errors: list[str],
|
|
|
422
425
|
delete_stmt=f"DELETE FROM {JWT_DB_TABLE}",
|
|
423
426
|
where_data={JWT_DB_COL_KID: oldest_id},
|
|
424
427
|
connection=db_conn,
|
|
428
|
+
committable=False,
|
|
425
429
|
logger=logger)
|
|
426
430
|
if errors:
|
|
427
431
|
raise RuntimeError("; ".join(errors))
|
|
@@ -436,6 +440,7 @@ def _jwt_persist_token(errors: list[str],
|
|
|
436
440
|
JWT_DB_COL_ALGORITHM: JWT_DEFAULT_ALGORITHM,
|
|
437
441
|
JWT_DB_COL_DECODER: urlsafe_b64encode(JWT_DECODING_KEY).decode()},
|
|
438
442
|
connection=db_conn,
|
|
443
|
+
committable=False,
|
|
439
444
|
logger=logger)
|
|
440
445
|
if errors:
|
|
441
446
|
raise RuntimeError("; ".join(errors))
|
|
@@ -446,6 +451,7 @@ def _jwt_persist_token(errors: list[str],
|
|
|
446
451
|
f"FROM {JWT_DB_TABLE}",
|
|
447
452
|
where_data={JWT_DB_COL_TOKEN: jwt_token},
|
|
448
453
|
connection=db_conn,
|
|
454
|
+
committable=False,
|
|
449
455
|
logger=logger)
|
|
450
456
|
if errors:
|
|
451
457
|
raise RuntimeError("; ".join(errors))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|