pypomes-jwt 1.2.1__tar.gz → 1.2.3__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.2.1 → pypomes_jwt-1.2.3}/PKG-INFO +4 -4
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/pyproject.toml +4 -4
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/src/pypomes_jwt/jwt_pomes.py +3 -3
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/src/pypomes_jwt/jwt_registry.py +18 -27
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/.gitignore +0 -0
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/LICENSE +0 -0
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/README.md +0 -0
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/src/pypomes_jwt/__init__.py +0 -0
- {pypomes_jwt-1.2.1 → pypomes_jwt-1.2.3}/src/pypomes_jwt/jwt_config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_jwt
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
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
|
|
@@ -10,8 +10,8 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Requires-Python: >=3.12
|
|
13
|
-
Requires-Dist: cryptography>=45.0.
|
|
13
|
+
Requires-Dist: cryptography>=45.0.4
|
|
14
14
|
Requires-Dist: flask>=3.1.1
|
|
15
15
|
Requires-Dist: pyjwt>=2.10.1
|
|
16
|
-
Requires-Dist: pypomes-core>=2.
|
|
17
|
-
Requires-Dist: pypomes-db>=2.2.
|
|
16
|
+
Requires-Dist: pypomes-core>=2.4.1
|
|
17
|
+
Requires-Dist: pypomes-db>=2.2.9
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "pypomes_jwt"
|
|
9
|
-
version = "1.2.
|
|
9
|
+
version = "1.2.3"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name="GT Nunes", email="wisecoder01@gmail.com" }
|
|
12
12
|
]
|
|
@@ -19,11 +19,11 @@ classifiers = [
|
|
|
19
19
|
"Operating System :: OS Independent"
|
|
20
20
|
]
|
|
21
21
|
dependencies = [
|
|
22
|
-
"cryptography>=45.0.
|
|
22
|
+
"cryptography>=45.0.4",
|
|
23
23
|
"Flask>=3.1.1",
|
|
24
24
|
"PyJWT>=2.10.1",
|
|
25
|
-
"pypomes_core>=2.
|
|
26
|
-
"pypomes_db>=2.2.
|
|
25
|
+
"pypomes_core>=2.4.1",
|
|
26
|
+
"pypomes_db>=2.2.9"
|
|
27
27
|
]
|
|
28
28
|
|
|
29
29
|
[project.urls]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import jwt
|
|
2
2
|
import sys
|
|
3
|
-
from base64 import
|
|
3
|
+
from base64 import b64decode
|
|
4
4
|
from flask import Request, Response, request
|
|
5
5
|
from logging import Logger
|
|
6
6
|
from pypomes_core import exc_format
|
|
@@ -23,7 +23,7 @@ def jwt_needed(func: callable) -> callable:
|
|
|
23
23
|
|
|
24
24
|
:param func: the function being decorated
|
|
25
25
|
"""
|
|
26
|
-
# ruff: noqa: ANN003
|
|
26
|
+
# ruff: noqa: ANN003 - Missing type annotation for *{name}
|
|
27
27
|
def wrapper(*args, **kwargs) -> Response:
|
|
28
28
|
response: Response = jwt_verify_request(request=request)
|
|
29
29
|
return response if response else func(*args, **kwargs)
|
|
@@ -197,7 +197,7 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
197
197
|
logger=logger)
|
|
198
198
|
if recs:
|
|
199
199
|
token_alg = recs[0][0]
|
|
200
|
-
token_decoder =
|
|
200
|
+
token_decoder = b64decode(recs[0][1])
|
|
201
201
|
elif op_errors:
|
|
202
202
|
if logger:
|
|
203
203
|
logger.error(msg=f"Error retrieving the token's decoder: {'; '.join(op_errors)}")
|
|
@@ -2,7 +2,7 @@ import jwt
|
|
|
2
2
|
import string
|
|
3
3
|
import sys
|
|
4
4
|
from base64 import b64encode
|
|
5
|
-
from datetime import datetime,
|
|
5
|
+
from datetime import datetime, UTC
|
|
6
6
|
from logging import Logger
|
|
7
7
|
from pypomes_core import str_random
|
|
8
8
|
from pypomes_db import (
|
|
@@ -196,7 +196,7 @@ class JwtRegistry:
|
|
|
196
196
|
current_claims["jti"] = str_random(size=32,
|
|
197
197
|
chars=string.ascii_letters + string.digits)
|
|
198
198
|
current_claims["sub"] = account_id
|
|
199
|
-
just_now: int = int(datetime.now(tz=
|
|
199
|
+
just_now: int = int(datetime.now(tz=UTC).timestamp())
|
|
200
200
|
current_claims["iat"] = just_now
|
|
201
201
|
if lead_interval:
|
|
202
202
|
current_claims["nbf"] = just_now + lead_interval
|
|
@@ -249,7 +249,7 @@ class JwtRegistry:
|
|
|
249
249
|
current_claims["sub"] = account_id
|
|
250
250
|
errors: list[str] = []
|
|
251
251
|
|
|
252
|
-
just_now: int = int(datetime.now(tz=
|
|
252
|
+
just_now: int = int(datetime.now(tz=UTC).timestamp())
|
|
253
253
|
current_claims["iat"] = just_now
|
|
254
254
|
lead_interval = account_data.get("lead-interval")
|
|
255
255
|
if lead_interval:
|
|
@@ -378,10 +378,9 @@ class JwtRegistry:
|
|
|
378
378
|
if logger:
|
|
379
379
|
logger.debug(msg=f"Read {len(recs)} token from storage for account '{account_id}'")
|
|
380
380
|
# remove the expired tokens
|
|
381
|
-
just_now: int = int(datetime.now(tz=
|
|
381
|
+
just_now: int = int(datetime.now(tz=UTC).timestamp())
|
|
382
382
|
oldest_ts: int = sys.maxsize
|
|
383
383
|
oldest_id: int | None = None
|
|
384
|
-
existing_ids: list[int] = []
|
|
385
384
|
expired: list[int] = []
|
|
386
385
|
for rec in recs:
|
|
387
386
|
token: str = rec[1]
|
|
@@ -403,9 +402,6 @@ class JwtRegistry:
|
|
|
403
402
|
oldest_ts = iat
|
|
404
403
|
oldest_id = token_id
|
|
405
404
|
|
|
406
|
-
# save token id
|
|
407
|
-
existing_ids.append(token_id)
|
|
408
|
-
|
|
409
405
|
# remove expired tokens from persistence
|
|
410
406
|
if expired:
|
|
411
407
|
db_delete(errors=errors,
|
|
@@ -436,32 +432,27 @@ class JwtRegistry:
|
|
|
436
432
|
logger.debug(msg="Oldest active token of account "
|
|
437
433
|
f"'{account_id}' removed from storage")
|
|
438
434
|
# persist token
|
|
439
|
-
db_insert(errors=errors,
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
435
|
+
col_kid: int = db_insert(errors=errors,
|
|
436
|
+
insert_stmt=f"INSERT INTO {JwtDbConfig.TABLE}",
|
|
437
|
+
insert_data={
|
|
438
|
+
JwtDbConfig.COL_ACCOUNT: account_id,
|
|
439
|
+
JwtDbConfig.COL_TOKEN: jwt_token,
|
|
440
|
+
JwtDbConfig.COL_ALGORITHM: JwtConfig.DEFAULT_ALGORITHM.value,
|
|
441
|
+
JwtDbConfig.COL_DECODER: b64encode(s=JwtConfig.DECODING_KEY.value).decode()
|
|
442
|
+
},
|
|
443
|
+
return_cols={JwtDbConfig.COL_KID: int},
|
|
444
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
445
|
+
connection=db_conn,
|
|
446
|
+
committable=False,
|
|
447
|
+
logger=logger)
|
|
451
448
|
if errors:
|
|
452
449
|
raise RuntimeError("; ".join(errors))
|
|
453
450
|
|
|
454
451
|
# obtain and return the token's storage id
|
|
455
|
-
# HAZARD: JWT_DB_COL_TOKEN's column type might prevent it for being used in a WHERE clause
|
|
456
|
-
where_clause: str | None = None
|
|
457
|
-
if existing_ids:
|
|
458
|
-
where_clause = f"{JwtDbConfig.COL_KID} NOT IN {existing_ids}"
|
|
459
|
-
where_clause = where_clause.replace("[", "(", 1).replace("]", ")", 1)
|
|
460
452
|
reply: list[tuple[int]] = db_select(errors=errors,
|
|
461
453
|
sel_stmt=f"SELECT {JwtDbConfig.COL_KID} "
|
|
462
454
|
f"FROM {JwtDbConfig.TABLE}",
|
|
463
|
-
|
|
464
|
-
where_data={JwtDbConfig.COL_ACCOUNT: account_id},
|
|
455
|
+
where_data={JwtDbConfig.COL_KID: col_kid},
|
|
465
456
|
min_count=1,
|
|
466
457
|
max_count=1,
|
|
467
458
|
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|