pypomes-jwt 1.1.7__tar.gz → 1.1.9__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.1.7 → pypomes_jwt-1.1.9}/PKG-INFO +4 -3
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/pyproject.toml +4 -3
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/src/pypomes_jwt/jwt_pomes.py +19 -17
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/src/pypomes_jwt/jwt_registry.py +8 -6
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/.gitignore +0 -0
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/LICENSE +0 -0
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/README.md +0 -0
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/src/pypomes_jwt/__init__.py +0 -0
- {pypomes_jwt-1.1.7 → pypomes_jwt-1.1.9}/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.1.
|
|
3
|
+
Version: 1.1.9
|
|
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,6 @@ 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>=2.0.
|
|
16
|
-
Requires-Dist: pypomes-db>=2.1.
|
|
15
|
+
Requires-Dist: pypomes-core>=2.0.6
|
|
16
|
+
Requires-Dist: pypomes-db>=2.1.5
|
|
17
|
+
Requires-Dist: pypomes-logging>=0.6.1
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "pypomes_jwt"
|
|
9
|
-
version = "1.1.
|
|
9
|
+
version = "1.1.9"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name="GT Nunes", email="wisecoder01@gmail.com" }
|
|
12
12
|
]
|
|
@@ -21,8 +21,9 @@ classifiers = [
|
|
|
21
21
|
dependencies = [
|
|
22
22
|
"PyJWT>=2.10.1",
|
|
23
23
|
"cryptography>=44.0.2",
|
|
24
|
-
"pypomes_core>=2.0.
|
|
25
|
-
"pypomes_db>=2.1.
|
|
24
|
+
"pypomes_core>=2.0.6",
|
|
25
|
+
"pypomes_db>=2.1.5",
|
|
26
|
+
"pypomes_logging>=0.6.1"
|
|
26
27
|
]
|
|
27
28
|
|
|
28
29
|
[project.urls]
|
|
@@ -8,6 +8,7 @@ from pypomes_db import (
|
|
|
8
8
|
DbEngine, db_connect, db_commit,
|
|
9
9
|
db_rollback, db_select, db_delete
|
|
10
10
|
)
|
|
11
|
+
from pypomes_logging import PYPOMES_LOGGER
|
|
11
12
|
from typing import Any
|
|
12
13
|
|
|
13
14
|
from .jwt_config import JwtConfig, JwtDbConfig
|
|
@@ -36,7 +37,7 @@ def jwt_needed(func: callable) -> callable:
|
|
|
36
37
|
|
|
37
38
|
def jwt_verify_request(request: Request) -> Response:
|
|
38
39
|
"""
|
|
39
|
-
Verify whether the HTTP *request* has the proper authorization, as per the JWT standard
|
|
40
|
+
Verify whether the HTTP *request* has the proper authorization, as per the JWT standard..
|
|
40
41
|
|
|
41
42
|
This implementation assumes that HTTP requests are handled with the *Flask* framework.
|
|
42
43
|
|
|
@@ -85,7 +86,7 @@ def jwt_set_account(account_id: str,
|
|
|
85
86
|
access_max_age: int = JwtConfig.ACCESS_MAX_AGE.value,
|
|
86
87
|
refresh_max_age: int = JwtConfig.REFRESH_MAX_AGE.value,
|
|
87
88
|
lead_interval: int = None,
|
|
88
|
-
logger: Logger =
|
|
89
|
+
logger: Logger = PYPOMES_LOGGER) -> None:
|
|
89
90
|
"""
|
|
90
91
|
Establish the data needed to obtain JWT tokens for *account_id*.
|
|
91
92
|
|
|
@@ -114,7 +115,7 @@ def jwt_set_account(account_id: str,
|
|
|
114
115
|
|
|
115
116
|
|
|
116
117
|
def jwt_remove_account(account_id: str,
|
|
117
|
-
logger: Logger =
|
|
118
|
+
logger: Logger = PYPOMES_LOGGER) -> bool:
|
|
118
119
|
"""
|
|
119
120
|
Remove from storage the JWT access data for *account_id*.
|
|
120
121
|
|
|
@@ -133,25 +134,26 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
133
134
|
token: str,
|
|
134
135
|
nature: str = None,
|
|
135
136
|
account_id: str = None,
|
|
136
|
-
logger: Logger =
|
|
137
|
+
logger: Logger = PYPOMES_LOGGER) -> dict[str, Any] | None:
|
|
137
138
|
"""
|
|
138
139
|
Verify if *token* ia a valid JWT token.
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
Attempt to validate non locally issued tokens will not succeed. If *nature* is provided,
|
|
142
|
+
validate whether *token* is of that nature. A token issued locally has the header claim *kid*
|
|
143
|
+
starting with *A* (for *Access*) or *R* (for *Refresh*), followed by its id in the token database,
|
|
144
|
+
or as a single letter in the range *[B-Z]*, less *R*. If the *kid* claim contains such an id,
|
|
145
|
+
then the cryptographic key needed for validation will be obtained from the token database.
|
|
146
|
+
Otherwise, the current decoding key is used.
|
|
146
147
|
|
|
147
|
-
On success, return the token's claims (header and payload), as documented in *jwt_get_claims()*
|
|
148
|
+
On success, return the token's claims (*header* and *payload*), as documented in *jwt_get_claims()*
|
|
149
|
+
On failure, *errors* will contain the reason(s) for rejecting *token*.
|
|
148
150
|
|
|
149
151
|
:param errors: incidental error messages
|
|
150
152
|
:param token: the token to be validated
|
|
151
153
|
:param nature: prefix identifying the nature of locally issued tokens
|
|
152
154
|
:param account_id: optionally, validate the token's account owner
|
|
153
155
|
:param logger: optional logger
|
|
154
|
-
:return: The token's claims (header and payload) if
|
|
156
|
+
:return: The token's claims (*header* and *payload*) if is valid, *None* otherwise
|
|
155
157
|
"""
|
|
156
158
|
# initialize the return variable
|
|
157
159
|
result: dict[str, Any] | None = None
|
|
@@ -257,7 +259,7 @@ def jwt_validate_token(errors: list[str] | None,
|
|
|
257
259
|
def jwt_revoke_token(errors: list[str] | None,
|
|
258
260
|
account_id: str,
|
|
259
261
|
token: str,
|
|
260
|
-
logger: Logger =
|
|
262
|
+
logger: Logger = PYPOMES_LOGGER) -> bool:
|
|
261
263
|
"""
|
|
262
264
|
Revoke the *refresh_token* associated with *account_id*.
|
|
263
265
|
|
|
@@ -310,7 +312,7 @@ def jwt_issue_token(errors: list[str] | None,
|
|
|
310
312
|
duration: int,
|
|
311
313
|
lead_interval: int = None,
|
|
312
314
|
claims: dict[str, Any] = None,
|
|
313
|
-
logger: Logger =
|
|
315
|
+
logger: Logger = PYPOMES_LOGGER) -> str:
|
|
314
316
|
"""
|
|
315
317
|
Issue or refresh, and return, a JWT token associated with *account_id*, of the specified *nature*.
|
|
316
318
|
|
|
@@ -361,7 +363,7 @@ def jwt_issue_token(errors: list[str] | None,
|
|
|
361
363
|
def jwt_issue_tokens(errors: list[str] | None,
|
|
362
364
|
account_id: str,
|
|
363
365
|
account_claims: dict[str, Any] = None,
|
|
364
|
-
logger: Logger =
|
|
366
|
+
logger: Logger = PYPOMES_LOGGER) -> dict[str, Any]:
|
|
365
367
|
"""
|
|
366
368
|
Issue the JWT token pair associated with *account_id*, for access and refresh operations.
|
|
367
369
|
|
|
@@ -415,7 +417,7 @@ def jwt_issue_tokens(errors: list[str] | None,
|
|
|
415
417
|
def jwt_refresh_tokens(errors: list[str] | None,
|
|
416
418
|
account_id: str,
|
|
417
419
|
refresh_token: str,
|
|
418
|
-
logger: Logger =
|
|
420
|
+
logger: Logger = PYPOMES_LOGGER) -> dict[str, Any]:
|
|
419
421
|
"""
|
|
420
422
|
Refresh the JWT token pair associated with *account_id*, for access and refresh operations.
|
|
421
423
|
|
|
@@ -513,7 +515,7 @@ def jwt_refresh_tokens(errors: list[str] | None,
|
|
|
513
515
|
|
|
514
516
|
def jwt_get_claims(errors: list[str] | None,
|
|
515
517
|
token: str,
|
|
516
|
-
logger: Logger =
|
|
518
|
+
logger: Logger = PYPOMES_LOGGER) -> dict[str, Any] | None:
|
|
517
519
|
"""
|
|
518
520
|
Retrieve and return the claims set of a JWT *token*.
|
|
519
521
|
|
|
@@ -9,6 +9,7 @@ from pypomes_db import (
|
|
|
9
9
|
DbEngine, db_connect, db_commit, db_rollback,
|
|
10
10
|
db_select, db_insert, db_update, db_delete
|
|
11
11
|
)
|
|
12
|
+
from pypomes_logging import PYPOMES_LOGGER
|
|
12
13
|
from threading import Lock
|
|
13
14
|
from typing import Any
|
|
14
15
|
|
|
@@ -88,7 +89,7 @@ class JwtRegistry:
|
|
|
88
89
|
access_max_age: int,
|
|
89
90
|
refresh_max_age: int,
|
|
90
91
|
lead_interval: int | None,
|
|
91
|
-
logger: Logger =
|
|
92
|
+
logger: Logger = PYPOMES_LOGGER) -> None:
|
|
92
93
|
"""
|
|
93
94
|
Add to storage the parameters needed to produce and validate JWT tokens for *account_id*.
|
|
94
95
|
|
|
@@ -152,7 +153,7 @@ class JwtRegistry:
|
|
|
152
153
|
duration: int,
|
|
153
154
|
lead_interval: int = None,
|
|
154
155
|
claims: dict[str, Any] = None,
|
|
155
|
-
logger: Logger =
|
|
156
|
+
logger: Logger = PYPOMES_LOGGER) -> str:
|
|
156
157
|
"""
|
|
157
158
|
Issue an return a JWT token associated with *account_id*.
|
|
158
159
|
|
|
@@ -212,7 +213,7 @@ class JwtRegistry:
|
|
|
212
213
|
account_id: str,
|
|
213
214
|
account_claims: dict[str, Any] = None,
|
|
214
215
|
db_conn: Any = None,
|
|
215
|
-
logger: Logger =
|
|
216
|
+
logger: Logger = PYPOMES_LOGGER) -> dict[str, Any]:
|
|
216
217
|
"""
|
|
217
218
|
Issue and return a JWT token pair associated with *account_id*.
|
|
218
219
|
|
|
@@ -319,7 +320,7 @@ class JwtRegistry:
|
|
|
319
320
|
|
|
320
321
|
def __get_account_data(self,
|
|
321
322
|
account_id: str,
|
|
322
|
-
logger: Logger =
|
|
323
|
+
logger: Logger = PYPOMES_LOGGER) -> dict[str, Any]:
|
|
323
324
|
"""
|
|
324
325
|
Retrieve the JWT access data associated with *account_id*.
|
|
325
326
|
|
|
@@ -341,7 +342,7 @@ class JwtRegistry:
|
|
|
341
342
|
def _jwt_persist_token(account_id: str,
|
|
342
343
|
jwt_token: str,
|
|
343
344
|
db_conn: Any,
|
|
344
|
-
logger: Logger =
|
|
345
|
+
logger: Logger = PYPOMES_LOGGER) -> int:
|
|
345
346
|
"""
|
|
346
347
|
Persist the given token, making sure that the account limit is complied with.
|
|
347
348
|
|
|
@@ -462,7 +463,8 @@ def _jwt_persist_token(account_id: str,
|
|
|
462
463
|
f"FROM {JwtDbConfig.TABLE}",
|
|
463
464
|
where_clause=where_clause,
|
|
464
465
|
where_data={JwtDbConfig.COL_ACCOUNT: account_id},
|
|
465
|
-
|
|
466
|
+
min_count=1,
|
|
467
|
+
max_count=1,
|
|
466
468
|
engine=DbEngine(JwtDbConfig.ENGINE),
|
|
467
469
|
connection=db_conn,
|
|
468
470
|
committable=False,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|