pypomes-jwt 1.0.9__tar.gz → 1.1.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-1.0.9 → pypomes_jwt-1.1.0}/PKG-INFO +3 -3
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/pyproject.toml +3 -3
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/src/pypomes_jwt/jwt_constants.py +9 -17
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/src/pypomes_jwt/jwt_pomes.py +12 -12
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/src/pypomes_jwt/jwt_registry.py +22 -22
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/.gitignore +0 -0
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/LICENSE +0 -0
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/README.md +0 -0
- {pypomes_jwt-1.0.9 → pypomes_jwt-1.1.0}/src/pypomes_jwt/__init__.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.1.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
|
|
@@ -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>=1.9.
|
|
16
|
-
Requires-Dist: pypomes-db>=2.0.
|
|
15
|
+
Requires-Dist: pypomes-core>=1.9.6
|
|
16
|
+
Requires-Dist: pypomes-db>=2.0.9
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "pypomes_jwt"
|
|
9
|
-
version = "1.0
|
|
9
|
+
version = "1.1.0"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name="GT Nunes", email="wisecoder01@gmail.com" }
|
|
12
12
|
]
|
|
@@ -21,8 +21,8 @@ classifiers = [
|
|
|
21
21
|
dependencies = [
|
|
22
22
|
"PyJWT>=2.10.1",
|
|
23
23
|
"cryptography>=44.0.2",
|
|
24
|
-
"pypomes_core>=1.9.
|
|
25
|
-
"pypomes_db>=2.0.
|
|
24
|
+
"pypomes_core>=1.9.6",
|
|
25
|
+
"pypomes_db>=2.0.9"
|
|
26
26
|
]
|
|
27
27
|
|
|
28
28
|
[project.urls]
|
|
@@ -23,10 +23,6 @@ class JwtParam(StrEnum):
|
|
|
23
23
|
ENCODING_KEY = "encoding-key"
|
|
24
24
|
REFRESH_MAX_AGE = "refresh-max-age"
|
|
25
25
|
|
|
26
|
-
def __str__(self) -> str: # noqa: D105
|
|
27
|
-
# noinspection PyTypeChecker
|
|
28
|
-
return self.value
|
|
29
|
-
|
|
30
26
|
|
|
31
27
|
class JwtDbParam(StrEnum):
|
|
32
28
|
"""
|
|
@@ -47,10 +43,6 @@ class JwtDbParam(StrEnum):
|
|
|
47
43
|
COL_KID = "col-kid"
|
|
48
44
|
COL_TOKEN = "col-token"
|
|
49
45
|
|
|
50
|
-
def __str__(self) -> str: # noqa: D105
|
|
51
|
-
# noinspection PyTypeChecker
|
|
52
|
-
return self.value
|
|
53
|
-
|
|
54
46
|
|
|
55
47
|
# recommended: allow the encode and decode keys to be generated anew when app starts
|
|
56
48
|
__encoding_key: bytes = env_get_bytes(key=f"{APP_PREFIX}_JWT_ENCODING_KEY",
|
|
@@ -87,7 +79,7 @@ _JWT_CONFIG: Final[dict[JwtParam, Any]] = {
|
|
|
87
79
|
JwtParam.REFRESH_MAX_AGE: env_get_int(key=f"{APP_PREFIX}_JWT_REFRESH_MAX_AGE",
|
|
88
80
|
def_value=86400)
|
|
89
81
|
}
|
|
90
|
-
|
|
82
|
+
_JWT_DB: Final[JwtDbParam, Any] = {
|
|
91
83
|
JwtDbParam.ENGINE: DbEngine(env_get_str(key=f"{APP_PREFIX}_JWT_DB_ENGINE")),
|
|
92
84
|
JwtDbParam.CLIENT: env_get_str(key=f"{APP_PREFIX}_JWT_DB_CLIENT"), # for Oracle, only
|
|
93
85
|
JwtDbParam.DRIVER: env_get_str(key=f"{APP_PREFIX}_JWT_DB_DRIVER"), # for SQLServer, only
|
|
@@ -105,12 +97,12 @@ _JWT_DATABASE: Final[JwtDbParam, Any] = {
|
|
|
105
97
|
}
|
|
106
98
|
|
|
107
99
|
# define and validate the database engine
|
|
108
|
-
if not db_setup(engine=
|
|
109
|
-
db_name=
|
|
110
|
-
db_user=
|
|
111
|
-
db_pwd=
|
|
112
|
-
db_host=
|
|
113
|
-
db_port=
|
|
114
|
-
db_client=
|
|
115
|
-
db_driver=
|
|
100
|
+
if not db_setup(engine=_JWT_DB[JwtDbParam.ENGINE],
|
|
101
|
+
db_name=_JWT_DB[JwtDbParam.NAME],
|
|
102
|
+
db_user=_JWT_DB[JwtDbParam.USER],
|
|
103
|
+
db_pwd=_JWT_DB[JwtDbParam.PWD],
|
|
104
|
+
db_host=_JWT_DB[JwtDbParam.HOST],
|
|
105
|
+
db_port=_JWT_DB[JwtDbParam.PORT],
|
|
106
|
+
db_client=_JWT_DB[JwtDbParam.CLIENT],
|
|
107
|
+
db_driver=_JWT_DB[JwtDbParam.DRIVER]):
|
|
116
108
|
stderr.write("Invalid database parameters\n")
|
|
@@ -10,7 +10,7 @@ from pypomes_db import (
|
|
|
10
10
|
from typing import Any
|
|
11
11
|
|
|
12
12
|
from .jwt_constants import (
|
|
13
|
-
JwtParam, JwtDbParam, _JWT_CONFIG,
|
|
13
|
+
JwtParam, JwtDbParam, _JWT_CONFIG, _JWT_DB
|
|
14
14
|
)
|
|
15
15
|
from .jwt_registry import JwtRegistry
|
|
16
16
|
|
|
@@ -180,14 +180,14 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
180
180
|
token_kid[0:1] in ["A", "R"] and token_kid[1:].isdigit():
|
|
181
181
|
# token was likely issued locally
|
|
182
182
|
where_data: dict[str, Any] = {
|
|
183
|
-
|
|
183
|
+
_JWT_DB[JwtDbParam.COL_KID]: int(token_kid[1:])
|
|
184
184
|
}
|
|
185
185
|
if account_id:
|
|
186
|
-
where_data[
|
|
186
|
+
where_data[_JWT_DB[JwtDbParam.COL_ACCOUNT]] = account_id
|
|
187
187
|
recs: list[tuple[str]] = db_select(errors=op_errors,
|
|
188
|
-
sel_stmt=f"SELECT {
|
|
189
|
-
f"{
|
|
190
|
-
f"FROM {
|
|
188
|
+
sel_stmt=f"SELECT {_JWT_DB[JwtDbParam.COL_ALGORITHM]}, "
|
|
189
|
+
f"{_JWT_DB[JwtDbParam.COL_DECODER]} "
|
|
190
|
+
f"FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
191
191
|
where_data=where_data,
|
|
192
192
|
logger=logger)
|
|
193
193
|
if recs:
|
|
@@ -282,10 +282,10 @@ def jwt_revoke_token(errors: list[str] | None,
|
|
|
282
282
|
op_errors.append("Invalid token")
|
|
283
283
|
else:
|
|
284
284
|
db_delete(errors=op_errors,
|
|
285
|
-
delete_stmt=f"DELETE FROM {
|
|
285
|
+
delete_stmt=f"DELETE FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
286
286
|
where_data={
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
_JWT_DB[JwtDbParam.COL_KID]: int(token_kid[1:]),
|
|
288
|
+
_JWT_DB[JwtDbParam.COL_ACCOUNT]: account_id
|
|
289
289
|
},
|
|
290
290
|
logger=logger)
|
|
291
291
|
if op_errors:
|
|
@@ -456,10 +456,10 @@ def jwt_refresh_tokens(errors: list[str] | None,
|
|
|
456
456
|
if db_conn:
|
|
457
457
|
# delete current refresh token
|
|
458
458
|
db_delete(errors=op_errors,
|
|
459
|
-
delete_stmt=f"DELETE FROM {
|
|
459
|
+
delete_stmt=f"DELETE FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
460
460
|
where_data={
|
|
461
|
-
|
|
462
|
-
|
|
461
|
+
_JWT_DB[JwtDbParam.COL_KID]: int(token_kid[1:]),
|
|
462
|
+
_JWT_DB[JwtDbParam.COL_ACCOUNT]: account_id
|
|
463
463
|
},
|
|
464
464
|
connection=db_conn,
|
|
465
465
|
committable=False,
|
|
@@ -13,7 +13,7 @@ from threading import Lock
|
|
|
13
13
|
from typing import Any
|
|
14
14
|
|
|
15
15
|
from .jwt_constants import (
|
|
16
|
-
JwtParam, JwtDbParam, _JWT_CONFIG,
|
|
16
|
+
JwtParam, JwtDbParam, _JWT_CONFIG, _JWT_DB
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
|
|
@@ -141,8 +141,8 @@ class JwtRegistry:
|
|
|
141
141
|
|
|
142
142
|
# remove from database
|
|
143
143
|
db_delete(errors=None,
|
|
144
|
-
delete_stmt=f"DELETE FROM {
|
|
145
|
-
where_data={
|
|
144
|
+
delete_stmt=f"DELETE FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
145
|
+
where_data={_JWT_DB[JwtDbParam.COL_ACCOUNT]: account_id},
|
|
146
146
|
logger=logger)
|
|
147
147
|
if logger:
|
|
148
148
|
if account_data:
|
|
@@ -298,9 +298,9 @@ 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 {
|
|
302
|
-
update_data={
|
|
303
|
-
where_data={
|
|
301
|
+
update_stmt=f"UPDATE {_JWT_DB[JwtDbParam.TABLE]}",
|
|
302
|
+
update_data={_JWT_DB[JwtDbParam.COL_TOKEN]: refresh_token},
|
|
303
|
+
where_data={_JWT_DB[JwtDbParam.COL_KID]: token_id},
|
|
304
304
|
connection=curr_conn,
|
|
305
305
|
committable=False,
|
|
306
306
|
logger=logger)
|
|
@@ -381,9 +381,9 @@ def _jwt_persist_token(account_id: str,
|
|
|
381
381
|
# noinspection PyTypeChecker
|
|
382
382
|
recs: list[tuple[int, str, str, str]] = \
|
|
383
383
|
db_select(errors=errors,
|
|
384
|
-
sel_stmt=f"SELECT {
|
|
385
|
-
f"FROM {
|
|
386
|
-
where_data={
|
|
384
|
+
sel_stmt=f"SELECT {_JWT_DB[JwtDbParam.COL_KID]}, {_JWT_DB[JwtDbParam.COL_TOKEN]} "
|
|
385
|
+
f"FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
386
|
+
where_data={_JWT_DB[JwtDbParam.COL_ACCOUNT]: account_id},
|
|
387
387
|
connection=db_conn,
|
|
388
388
|
committable=False,
|
|
389
389
|
logger=logger)
|
|
@@ -424,8 +424,8 @@ def _jwt_persist_token(account_id: str,
|
|
|
424
424
|
# remove expired tokens from persistence
|
|
425
425
|
if expired:
|
|
426
426
|
db_delete(errors=errors,
|
|
427
|
-
delete_stmt=f"DELETE FROM {
|
|
428
|
-
where_data={
|
|
427
|
+
delete_stmt=f"DELETE FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
428
|
+
where_data={_JWT_DB[JwtDbParam.COL_KID]: expired},
|
|
429
429
|
connection=db_conn,
|
|
430
430
|
committable=False,
|
|
431
431
|
logger=logger)
|
|
@@ -438,8 +438,8 @@ def _jwt_persist_token(account_id: str,
|
|
|
438
438
|
if 0 < _JWT_CONFIG[JwtParam.ACCOUNT_LIMIT] <= len(recs) - len(expired):
|
|
439
439
|
# delete the oldest token to make way for the new one
|
|
440
440
|
db_delete(errors=errors,
|
|
441
|
-
delete_stmt=f"DELETE FROM {
|
|
442
|
-
where_data={
|
|
441
|
+
delete_stmt=f"DELETE FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
442
|
+
where_data={_JWT_DB[JwtDbParam.COL_KID]: oldest_id},
|
|
443
443
|
connection=db_conn,
|
|
444
444
|
committable=False,
|
|
445
445
|
logger=logger)
|
|
@@ -450,12 +450,12 @@ def _jwt_persist_token(account_id: str,
|
|
|
450
450
|
f"'{account_id}' removed from storage")
|
|
451
451
|
# persist token
|
|
452
452
|
db_insert(errors=errors,
|
|
453
|
-
insert_stmt=f"INSERT INTO {
|
|
453
|
+
insert_stmt=f"INSERT INTO {_JWT_DB[JwtDbParam.TABLE]}",
|
|
454
454
|
insert_data={
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
455
|
+
_JWT_DB[JwtDbParam.COL_ACCOUNT]: account_id,
|
|
456
|
+
_JWT_DB[JwtDbParam.COL_TOKEN]: jwt_token,
|
|
457
|
+
_JWT_DB[JwtDbParam.COL_ALGORITHM]: _JWT_CONFIG[JwtParam.DEFAULT_ALGORITHM],
|
|
458
|
+
_JWT_DB[JwtDbParam.COL_DECODER]: urlsafe_b64encode(_JWT_CONFIG[JwtParam.DECODING_KEY]).decode()
|
|
459
459
|
},
|
|
460
460
|
connection=db_conn,
|
|
461
461
|
committable=False,
|
|
@@ -467,13 +467,13 @@ def _jwt_persist_token(account_id: str,
|
|
|
467
467
|
# HAZARD: JWT_DB_COL_TOKEN's column type might prevent it for being used in a WHERE clause
|
|
468
468
|
where_clause: str | None = None
|
|
469
469
|
if existing_ids:
|
|
470
|
-
where_clause = f"{
|
|
470
|
+
where_clause = f"{_JWT_DB[JwtDbParam.COL_KID]} NOT IN {existing_ids}"
|
|
471
471
|
where_clause = where_clause.replace("[", "(", 1).replace("]", ")", 1)
|
|
472
472
|
reply: list[tuple[int]] = db_select(errors=errors,
|
|
473
|
-
sel_stmt=f"SELECT {
|
|
474
|
-
f"FROM {
|
|
473
|
+
sel_stmt=f"SELECT {_JWT_DB[JwtDbParam.COL_KID]} "
|
|
474
|
+
f"FROM {_JWT_DB[JwtDbParam.TABLE]}",
|
|
475
475
|
where_clause=where_clause,
|
|
476
|
-
where_data={
|
|
476
|
+
where_data={_JWT_DB[JwtDbParam.COL_ACCOUNT]: account_id},
|
|
477
477
|
require_count=1,
|
|
478
478
|
connection=db_conn,
|
|
479
479
|
committable=False,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|