pypomes-jwt 1.1.3__py3-none-any.whl → 1.1.4__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.
Potentially problematic release.
This version of pypomes-jwt might be problematic. Click here for more details.
- pypomes_jwt/jwt_configuration.py +3 -4
- pypomes_jwt/jwt_pomes.py +17 -16
- pypomes_jwt/jwt_registry.py +30 -30
- {pypomes_jwt-1.1.3.dist-info → pypomes_jwt-1.1.4.dist-info}/METADATA +3 -3
- pypomes_jwt-1.1.4.dist-info/RECORD +8 -0
- pypomes_jwt-1.1.3.dist-info/RECORD +0 -8
- {pypomes_jwt-1.1.3.dist-info → pypomes_jwt-1.1.4.dist-info}/WHEEL +0 -0
- {pypomes_jwt-1.1.3.dist-info → pypomes_jwt-1.1.4.dist-info}/licenses/LICENSE +0 -0
pypomes_jwt/jwt_configuration.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
from cryptography.hazmat.primitives import serialization
|
|
2
2
|
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
3
3
|
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey
|
|
4
|
-
from enum import Enum
|
|
4
|
+
from enum import Enum, StrEnum
|
|
5
5
|
from pypomes_core import (
|
|
6
6
|
APP_PREFIX,
|
|
7
7
|
env_get_str, env_get_bytes, env_get_int
|
|
8
8
|
)
|
|
9
|
-
from pypomes_db import DbEngine
|
|
10
9
|
from secrets import token_bytes
|
|
11
10
|
|
|
12
11
|
|
|
@@ -51,11 +50,11 @@ class JwtConfig(Enum):
|
|
|
51
50
|
def_value=86400)
|
|
52
51
|
|
|
53
52
|
|
|
54
|
-
class JwtDbConfig(
|
|
53
|
+
class JwtDbConfig(StrEnum):
|
|
55
54
|
"""
|
|
56
55
|
Parameters for JWT databse connection.
|
|
57
56
|
"""
|
|
58
|
-
ENGINE: str =
|
|
57
|
+
ENGINE: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_ENGINE")
|
|
59
58
|
TABLE: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_TABLE")
|
|
60
59
|
COL_ACCOUNT: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_ACCOUNT")
|
|
61
60
|
COL_ALGORITHM: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_ALGORITHM")
|
pypomes_jwt/jwt_pomes.py
CHANGED
|
@@ -5,7 +5,8 @@ from flask import Request, Response, request
|
|
|
5
5
|
from logging import Logger
|
|
6
6
|
from pypomes_core import exc_format
|
|
7
7
|
from pypomes_db import (
|
|
8
|
-
db_connect, db_commit,
|
|
8
|
+
DbEngine, db_connect, db_commit,
|
|
9
|
+
db_rollback, db_select, db_delete
|
|
9
10
|
)
|
|
10
11
|
from typing import Any
|
|
11
12
|
|
|
@@ -177,15 +178,15 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
177
178
|
elif token_kid and len(token_kid) > 1 and \
|
|
178
179
|
token_kid[0:1] in ["A", "R"] and token_kid[1:].isdigit():
|
|
179
180
|
# token was likely issued locally
|
|
180
|
-
where_data: dict[str, Any] = {JwtDbConfig.COL_KID
|
|
181
|
+
where_data: dict[str, Any] = {JwtDbConfig.COL_KID: int(token_kid[1:])}
|
|
181
182
|
if account_id:
|
|
182
|
-
where_data[JwtDbConfig.COL_ACCOUNT
|
|
183
|
+
where_data[JwtDbConfig.COL_ACCOUNT] = account_id
|
|
183
184
|
recs: list[tuple[str]] = db_select(errors=op_errors,
|
|
184
|
-
sel_stmt=f"SELECT {JwtDbConfig.COL_ALGORITHM
|
|
185
|
-
f"{JwtDbConfig.COL_DECODER
|
|
186
|
-
f"FROM {JwtDbConfig.TABLE
|
|
185
|
+
sel_stmt=f"SELECT {JwtDbConfig.COL_ALGORITHM}, "
|
|
186
|
+
f"{JwtDbConfig.COL_DECODER} "
|
|
187
|
+
f"FROM {JwtDbConfig.TABLE}",
|
|
187
188
|
where_data=where_data,
|
|
188
|
-
engine=JwtDbConfig.ENGINE
|
|
189
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
189
190
|
logger=logger)
|
|
190
191
|
if recs:
|
|
191
192
|
token_alg = recs[0][0]
|
|
@@ -279,12 +280,12 @@ def jwt_revoke_token(errors: list[str] | None,
|
|
|
279
280
|
op_errors.append("Invalid token")
|
|
280
281
|
else:
|
|
281
282
|
db_delete(errors=op_errors,
|
|
282
|
-
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE
|
|
283
|
+
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
|
|
283
284
|
where_data={
|
|
284
|
-
JwtDbConfig.COL_KID
|
|
285
|
-
JwtDbConfig.COL_ACCOUNT
|
|
285
|
+
JwtDbConfig.COL_KID: int(token_kid[1:]),
|
|
286
|
+
JwtDbConfig.COL_ACCOUNT: account_id
|
|
286
287
|
},
|
|
287
|
-
engine=JwtDbConfig.ENGINE
|
|
288
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
288
289
|
logger=logger)
|
|
289
290
|
if op_errors:
|
|
290
291
|
if logger:
|
|
@@ -450,17 +451,17 @@ def jwt_refresh_tokens(errors: list[str] | None,
|
|
|
450
451
|
# start the database transaction
|
|
451
452
|
db_conn: Any = db_connect(errors=op_errors,
|
|
452
453
|
autocommit=False,
|
|
453
|
-
engine=JwtDbConfig.ENGINE
|
|
454
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
454
455
|
logger=logger)
|
|
455
456
|
if db_conn:
|
|
456
457
|
# delete current refresh token
|
|
457
458
|
db_delete(errors=op_errors,
|
|
458
|
-
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE
|
|
459
|
+
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
|
|
459
460
|
where_data={
|
|
460
|
-
JwtDbConfig.COL_KID
|
|
461
|
-
JwtDbConfig.COL_ACCOUNT
|
|
461
|
+
JwtDbConfig.COL_KID: int(token_kid[1:]),
|
|
462
|
+
JwtDbConfig.COL_ACCOUNT: account_id
|
|
462
463
|
},
|
|
463
|
-
engine=JwtDbConfig.ENGINE
|
|
464
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
464
465
|
connection=db_conn,
|
|
465
466
|
committable=False,
|
|
466
467
|
logger=logger)
|
pypomes_jwt/jwt_registry.py
CHANGED
|
@@ -6,7 +6,7 @@ from datetime import datetime, timezone
|
|
|
6
6
|
from logging import Logger
|
|
7
7
|
from pypomes_core import str_random
|
|
8
8
|
from pypomes_db import (
|
|
9
|
-
db_connect, db_commit, db_rollback,
|
|
9
|
+
DbEngine, db_connect, db_commit, db_rollback,
|
|
10
10
|
db_select, db_insert, db_update, db_delete
|
|
11
11
|
)
|
|
12
12
|
from threading import Lock
|
|
@@ -139,9 +139,9 @@ class JwtRegistry:
|
|
|
139
139
|
|
|
140
140
|
# remove from database
|
|
141
141
|
db_delete(errors=None,
|
|
142
|
-
delete_stmt=f"DELETE FROM {JwtDbConfig
|
|
143
|
-
where_data={JwtDbConfig.COL_ACCOUNT
|
|
144
|
-
engine=JwtDbConfig.ENGINE
|
|
142
|
+
delete_stmt=f"DELETE FROM {JwtDbConfig}",
|
|
143
|
+
where_data={JwtDbConfig.COL_ACCOUNT: account_id},
|
|
144
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
145
145
|
logger=logger)
|
|
146
146
|
if logger:
|
|
147
147
|
if account_data:
|
|
@@ -283,7 +283,7 @@ class JwtRegistry:
|
|
|
283
283
|
# make sure to have a database connection
|
|
284
284
|
curr_conn: Any = db_conn or db_connect(errors=errors,
|
|
285
285
|
autocommit=False,
|
|
286
|
-
engine=JwtDbConfig.ENGINE
|
|
286
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
287
287
|
logger=logger)
|
|
288
288
|
if curr_conn:
|
|
289
289
|
# persist the candidate token (may raise an exception)
|
|
@@ -298,10 +298,10 @@ class JwtRegistry:
|
|
|
298
298
|
headers={"kid": f"R{token_id}"})
|
|
299
299
|
# persist it
|
|
300
300
|
db_update(errors=errors,
|
|
301
|
-
update_stmt=f"UPDATE {JwtDbConfig.TABLE
|
|
302
|
-
update_data={JwtDbConfig.COL_TOKEN
|
|
303
|
-
where_data={JwtDbConfig.COL_KID
|
|
304
|
-
engine=JwtDbConfig.ENGINE
|
|
301
|
+
update_stmt=f"UPDATE {JwtDbConfig.TABLE}",
|
|
302
|
+
update_data={JwtDbConfig.COL_TOKEN: refresh_token},
|
|
303
|
+
where_data={JwtDbConfig.COL_KID: token_id},
|
|
304
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
305
305
|
connection=curr_conn,
|
|
306
306
|
committable=False,
|
|
307
307
|
logger=logger)
|
|
@@ -382,10 +382,10 @@ def _jwt_persist_token(account_id: str,
|
|
|
382
382
|
# noinspection PyTypeChecker
|
|
383
383
|
recs: list[tuple[int, str, str, str]] = \
|
|
384
384
|
db_select(errors=errors,
|
|
385
|
-
sel_stmt=f"SELECT {JwtDbConfig.COL_KID
|
|
386
|
-
f"FROM {JwtDbConfig.TABLE
|
|
387
|
-
where_data={JwtDbConfig.COL_ACCOUNT
|
|
388
|
-
engine=JwtDbConfig.ENGINE
|
|
385
|
+
sel_stmt=f"SELECT {JwtDbConfig.COL_KID}, {JwtDbConfig.COL_TOKEN} "
|
|
386
|
+
f"FROM {JwtDbConfig.TABLE}",
|
|
387
|
+
where_data={JwtDbConfig.COL_ACCOUNT: account_id},
|
|
388
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
389
389
|
connection=db_conn,
|
|
390
390
|
committable=False,
|
|
391
391
|
logger=logger)
|
|
@@ -426,9 +426,9 @@ def _jwt_persist_token(account_id: str,
|
|
|
426
426
|
# remove expired tokens from persistence
|
|
427
427
|
if expired:
|
|
428
428
|
db_delete(errors=errors,
|
|
429
|
-
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE
|
|
430
|
-
where_data={JwtDbConfig.COL_KID
|
|
431
|
-
engine=JwtDbConfig.ENGINE
|
|
429
|
+
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
|
|
430
|
+
where_data={JwtDbConfig.COL_KID: expired},
|
|
431
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
432
432
|
connection=db_conn,
|
|
433
433
|
committable=False,
|
|
434
434
|
logger=logger)
|
|
@@ -441,9 +441,9 @@ def _jwt_persist_token(account_id: str,
|
|
|
441
441
|
if 0 < JwtConfig.ACCOUNT_LIMIT.value <= len(recs) - len(expired):
|
|
442
442
|
# delete the oldest token to make way for the new one
|
|
443
443
|
db_delete(errors=errors,
|
|
444
|
-
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE
|
|
445
|
-
where_data={JwtDbConfig.COL_KID
|
|
446
|
-
engine=JwtDbConfig.ENGINE
|
|
444
|
+
delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
|
|
445
|
+
where_data={JwtDbConfig.COL_KID: oldest_id},
|
|
446
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
447
447
|
connection=db_conn,
|
|
448
448
|
committable=False,
|
|
449
449
|
logger=logger)
|
|
@@ -454,14 +454,14 @@ def _jwt_persist_token(account_id: str,
|
|
|
454
454
|
f"'{account_id}' removed from storage")
|
|
455
455
|
# persist token
|
|
456
456
|
db_insert(errors=errors,
|
|
457
|
-
insert_stmt=f"INSERT INTO {JwtDbConfig.TABLE
|
|
457
|
+
insert_stmt=f"INSERT INTO {JwtDbConfig.TABLE}",
|
|
458
458
|
insert_data={
|
|
459
|
-
JwtDbConfig.COL_ACCOUNT
|
|
460
|
-
JwtDbConfig.COL_TOKEN
|
|
461
|
-
JwtDbConfig.COL_ALGORITHM
|
|
462
|
-
JwtDbConfig.COL_DECODER
|
|
459
|
+
JwtDbConfig.COL_ACCOUNT: account_id,
|
|
460
|
+
JwtDbConfig.COL_TOKEN: jwt_token,
|
|
461
|
+
JwtDbConfig.COL_ALGORITHM: JwtConfig.DEFAULT_ALGORITHM.value,
|
|
462
|
+
JwtDbConfig.COL_DECODER: urlsafe_b64encode(s=JwtConfig.DECODING_KEY.value).decode()
|
|
463
463
|
},
|
|
464
|
-
engine=JwtDbConfig.ENGINE
|
|
464
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
465
465
|
connection=db_conn,
|
|
466
466
|
committable=False,
|
|
467
467
|
logger=logger)
|
|
@@ -472,15 +472,15 @@ def _jwt_persist_token(account_id: str,
|
|
|
472
472
|
# HAZARD: JWT_DB_COL_TOKEN's column type might prevent it for being used in a WHERE clause
|
|
473
473
|
where_clause: str | None = None
|
|
474
474
|
if existing_ids:
|
|
475
|
-
where_clause = f"{JwtDbConfig.COL_KID
|
|
475
|
+
where_clause = f"{JwtDbConfig.COL_KID} NOT IN {existing_ids}"
|
|
476
476
|
where_clause = where_clause.replace("[", "(", 1).replace("]", ")", 1)
|
|
477
477
|
reply: list[tuple[int]] = db_select(errors=errors,
|
|
478
|
-
sel_stmt=f"SELECT {JwtDbConfig.COL_KID
|
|
479
|
-
f"FROM {JwtDbConfig.TABLE
|
|
478
|
+
sel_stmt=f"SELECT {JwtDbConfig.COL_KID} "
|
|
479
|
+
f"FROM {JwtDbConfig.TABLE}",
|
|
480
480
|
where_clause=where_clause,
|
|
481
|
-
where_data={JwtDbConfig.COL_ACCOUNT
|
|
481
|
+
where_data={JwtDbConfig.COL_ACCOUNT: account_id},
|
|
482
482
|
require_count=1,
|
|
483
|
-
engine=JwtDbConfig.ENGINE
|
|
483
|
+
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
484
484
|
connection=db_conn,
|
|
485
485
|
committable=False,
|
|
486
486
|
logger=logger)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_jwt
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.4
|
|
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
|
|
@@ -12,5 +12,5 @@ Classifier: Programming Language :: Python :: 3
|
|
|
12
12
|
Requires-Python: >=3.12
|
|
13
13
|
Requires-Dist: cryptography>=44.0.2
|
|
14
14
|
Requires-Dist: pyjwt>=2.10.1
|
|
15
|
-
Requires-Dist: pypomes-core>=
|
|
16
|
-
Requires-Dist: pypomes-db>=2.
|
|
15
|
+
Requires-Dist: pypomes-core>=2.0.3
|
|
16
|
+
Requires-Dist: pypomes-db>=2.1.1
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pypomes_jwt/__init__.py,sha256=g4tjg7gt5_vwiHM_6-T6Ji4XYJ5py9RuzGmF2Z-qlXI,800
|
|
2
|
+
pypomes_jwt/jwt_configuration.py,sha256=mtihd58_O00FuFXcNBKsabftG6UHu3Cj24i6cZXoskc,3096
|
|
3
|
+
pypomes_jwt/jwt_pomes.py,sha256=oix-QLxno663wioj5W13zJahzzlQqTmtolkLqPFtKfI,23524
|
|
4
|
+
pypomes_jwt/jwt_registry.py,sha256=8M4Ixhf3FQedqWS6icpJVe-7Z9KMd9qc9BjECDTZ_tU,23597
|
|
5
|
+
pypomes_jwt-1.1.4.dist-info/METADATA,sha256=h4iHBGBfwx-3FFHkHFEOKvg58aFxfiXcTp6FGhfpRNI,632
|
|
6
|
+
pypomes_jwt-1.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
pypomes_jwt-1.1.4.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
|
|
8
|
+
pypomes_jwt-1.1.4.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
pypomes_jwt/__init__.py,sha256=g4tjg7gt5_vwiHM_6-T6Ji4XYJ5py9RuzGmF2Z-qlXI,800
|
|
2
|
-
pypomes_jwt/jwt_configuration.py,sha256=mqTPblkfb4RXAzUe28T2gCk1auCYVY7gIlz2iFK4JSg,3127
|
|
3
|
-
pypomes_jwt/jwt_pomes.py,sha256=OkkzKc87eviEovAPIlGJlFlMIKooSivTB9LvX2137mg,23559
|
|
4
|
-
pypomes_jwt/jwt_registry.py,sha256=NEIYE15j4MnKaGVKp42WjriBzekvDZVTHFXP08EOcXA,23687
|
|
5
|
-
pypomes_jwt-1.1.3.dist-info/METADATA,sha256=dm8aTZMrvDbHxcpLvp07PDw1F_pZSef6DLeXnoVPqbo,632
|
|
6
|
-
pypomes_jwt-1.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
pypomes_jwt-1.1.3.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
|
|
8
|
-
pypomes_jwt-1.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|