pypomes-jwt 0.7.2__tar.gz → 0.7.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-0.7.2 → pypomes_jwt-0.7.3}/PKG-INFO +1 -1
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/pyproject.toml +1 -1
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/src/pypomes_jwt/__init__.py +2 -0
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/src/pypomes_jwt/jwt_constants.py +10 -5
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/src/pypomes_jwt/jwt_data.py +11 -10
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/src/pypomes_jwt/jwt_pomes.py +2 -2
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/.gitignore +0 -0
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/LICENSE +0 -0
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/README.md +0 -0
- {pypomes_jwt-0.7.2 → pypomes_jwt-0.7.3}/src/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_jwt
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from .jwt_constants import (
|
|
2
2
|
JWT_DB_ENGINE, JWT_DB_HOST, JWT_DB_NAME,
|
|
3
3
|
JWT_DB_PORT, JWT_DB_USER, JWT_DB_PWD,
|
|
4
|
+
JWT_DB_TABLE, JWT_DB_COL_ACCOUNT, JWT_DB_COL_TOKEN,
|
|
4
5
|
JWT_ACCESS_MAX_AGE, JWT_REFRESH_MAX_AGE,
|
|
5
6
|
JWT_ENCODING_KEY, JWT_DECODING_KEY
|
|
6
7
|
)
|
|
@@ -14,6 +15,7 @@ __all__ = [
|
|
|
14
15
|
# jwt_constants
|
|
15
16
|
"JWT_DB_ENGINE", "JWT_DB_HOST", "JWT_DB_NAME",
|
|
16
17
|
"JWT_DB_PORT", "JWT_DB_USER", "JWT_DB_PWD",
|
|
18
|
+
"JWT_DB_TABLE", "JWT_DB_COL_ACCOUNT", "JWT_DB_COL_TOKEN",
|
|
17
19
|
"JWT_ACCESS_MAX_AGE", "JWT_REFRESH_MAX_AGE",
|
|
18
20
|
"JWT_ENCODING_KEY", "JWT_DECODING_KEY",
|
|
19
21
|
# jwt_pomes
|
|
@@ -16,12 +16,14 @@ JWT_DB_USER: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_USER")
|
|
|
16
16
|
JWT_DB_PWD: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_PWD")
|
|
17
17
|
JWT_DB_CLIENT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_CLIENT") # for Oracle, only
|
|
18
18
|
JWT_DB_DRIVER: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_DRIVER") # for SQLServer, only
|
|
19
|
-
JWT_DB_TABLE: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_TABLE"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
JWT_DB_TABLE: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_TABLE",
|
|
20
|
+
def_value="jwt_token")
|
|
21
|
+
JWT_DB_COL_ACCOUNT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_ACCOUNT",
|
|
22
|
+
def_value="account_id")
|
|
23
|
+
JWT_DB_COL_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_TOKEN",
|
|
24
|
+
def_value="token")
|
|
25
|
+
# define the database engine
|
|
23
26
|
__db_engine: str | None = env_get_str(key=f"{APP_PREFIX}_JWT_DB_ENGINE")
|
|
24
|
-
__rotate_tokens: bool = False
|
|
25
27
|
if __db_engine:
|
|
26
28
|
from pypomes_db import DbEngine, db_setup, db_assert_access, db_delete
|
|
27
29
|
from sys import stderr
|
|
@@ -42,6 +44,7 @@ if __db_engine:
|
|
|
42
44
|
else:
|
|
43
45
|
stderr.write("Invalid database parameters\n")
|
|
44
46
|
__db_engine = None
|
|
47
|
+
# if set to 'None', no further attempt will be made to access the database
|
|
45
48
|
JWT_DB_ENGINE: Final[DbEngine] = DbEngine(__db_engine) if __db_engine else None
|
|
46
49
|
|
|
47
50
|
# one of HS256, HS512, RSA256, RSA512
|
|
@@ -53,6 +56,8 @@ JWT_ACCESS_MAX_AGE: Final[int] = env_get_int(key=f"{APP_PREFIX}_JWT_ACCESS_MAX_A
|
|
|
53
56
|
# recommended: at least 2 hours (set to 24 hours)
|
|
54
57
|
JWT_REFRESH_MAX_AGE: Final[int] = env_get_int(key=f"{APP_PREFIX}_JWT_REFRESH_MAX_AGE",
|
|
55
58
|
def_value=86400)
|
|
59
|
+
JWT_ROTATE_TOKENS: Final[bool] = env_get_bool(key=f"{APP_PREFIX}_JWT_ROTATE_TOKENS",
|
|
60
|
+
def_value=True)
|
|
56
61
|
|
|
57
62
|
# recommended: allow the encode and decode keys to be generated anew when app starts
|
|
58
63
|
__encoding_key: bytes = env_get_bytes(key=f"{APP_PREFIX}_JWT_ENCODE_KEY")
|
|
@@ -9,8 +9,8 @@ from threading import Lock
|
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
11
|
from .jwt_constants import (
|
|
12
|
-
JWT_DEFAULT_ALGORITHM, JWT_ENCODING_KEY,
|
|
13
|
-
|
|
12
|
+
JWT_DEFAULT_ALGORITHM, JWT_ENCODING_KEY, JWT_ROTATE_TOKENS,
|
|
13
|
+
JWT_DB_ENGINE, JWT_DB_TABLE, JWT_DB_COL_ACCOUNT, JWT_DB_COL_TOKEN
|
|
14
14
|
)
|
|
15
15
|
|
|
16
16
|
|
|
@@ -232,14 +232,15 @@ class JwtData:
|
|
|
232
232
|
if JWT_ROTATE_TOKENS:
|
|
233
233
|
db_delete(errors=errors,
|
|
234
234
|
delete_stmt=f"DELETE FROM {JWT_DB_TABLE} "
|
|
235
|
-
f"WHERE
|
|
235
|
+
f"WHERE {JWT_DB_COL_ACCOUNT} = '{account_id}'",
|
|
236
236
|
logger=logger)
|
|
237
237
|
else:
|
|
238
|
-
recs: list[tuple[str]] =
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
recs: list[tuple[str]] = \
|
|
239
|
+
db_select(errors=errors,
|
|
240
|
+
sel_stmt=f"SELECT token FROM {JWT_DB_TABLE} "
|
|
241
|
+
f"WHERE {JWT_DB_COL_ACCOUNT} = '{account_id}'",
|
|
242
|
+
max_count=1,
|
|
243
|
+
logger=logger)
|
|
243
244
|
if recs:
|
|
244
245
|
refresh_token = recs[0][0]
|
|
245
246
|
if errors:
|
|
@@ -259,8 +260,8 @@ class JwtData:
|
|
|
259
260
|
from pypomes_db import db_insert
|
|
260
261
|
db_insert(errors=errors,
|
|
261
262
|
insert_stmt=f"INSERT INTO {JWT_DB_TABLE}",
|
|
262
|
-
insert_data={
|
|
263
|
-
|
|
263
|
+
insert_data={JWT_DB_COL_ACCOUNT: account_id,
|
|
264
|
+
JWT_DB_COL_TOKEN: refresh_token},
|
|
264
265
|
logger=logger)
|
|
265
266
|
if errors:
|
|
266
267
|
raise RuntimeError(" - ".join(errors))
|
|
@@ -6,7 +6,7 @@ from typing import Any, Literal
|
|
|
6
6
|
from .jwt_constants import (
|
|
7
7
|
JWT_ACCESS_MAX_AGE, JWT_REFRESH_MAX_AGE,
|
|
8
8
|
JWT_DEFAULT_ALGORITHM, JWT_DECODING_KEY,
|
|
9
|
-
JWT_DB_ENGINE, JWT_DB_TABLE
|
|
9
|
+
JWT_DB_ENGINE, JWT_DB_TABLE, JWT_DB_COL_ACCOUNT
|
|
10
10
|
)
|
|
11
11
|
from .jwt_data import JwtData
|
|
12
12
|
|
|
@@ -176,7 +176,7 @@ def jwt_revoke_tokens(errors: list[str] | None,
|
|
|
176
176
|
if JWT_DB_ENGINE:
|
|
177
177
|
from pypomes_db import db_delete
|
|
178
178
|
delete_stmt: str = (f"DELETE FROM {JWT_DB_TABLE} "
|
|
179
|
-
f"WHERE
|
|
179
|
+
f"WHERE {JWT_DB_COL_ACCOUNT} = '{account_id}'")
|
|
180
180
|
db_delete(errors=op_errors,
|
|
181
181
|
delete_stmt=delete_stmt,
|
|
182
182
|
logger=logger)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|