pypomes-jwt 1.1.7__py3-none-any.whl → 1.1.9__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_pomes.py CHANGED
@@ -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 = None) -> None:
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 = None) -> bool:
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 = None) -> dict[str, Any] | None:
137
+ logger: Logger = PYPOMES_LOGGER) -> dict[str, Any] | None:
137
138
  """
138
139
  Verify if *token* ia a valid JWT token.
139
140
 
140
- Raise an appropriate exception if validation failed. Attempt to validate non locally issued tokens
141
- will not succeed. if *nature* is provided, validate whether *token* is of that nature.
142
- A token issued locally has the header claim *kid* starting with *A* (for *Access*) or *R* (for *Refresh*),
143
- followed by its id in the token database, or as a single letter in the range *[B-Z]*, less *R*.
144
- If the *kid* claim contains such an id, then the cryptographic key needed for validation
145
- will be obtained from the token database. Otherwise, the current decoding key is used.
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 if is valid, *None* otherwise
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 = None) -> bool:
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 = None) -> str:
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 = None) -> dict[str, Any]:
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 = None) -> dict[str, Any]:
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 = None) -> dict[str, Any] | None:
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 = None) -> None:
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 = None) -> str:
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 = None) -> dict[str, Any]:
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 = None) -> dict[str, Any]:
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 = None) -> int:
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
- require_count=1,
466
+ min_count=1,
467
+ max_count=1,
466
468
  engine=DbEngine(JwtDbConfig.ENGINE),
467
469
  connection=db_conn,
468
470
  committable=False,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 1.1.7
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.5
16
- Requires-Dist: pypomes-db>=2.1.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
@@ -0,0 +1,8 @@
1
+ pypomes_jwt/__init__.py,sha256=NZzjWKnhjxNuoE32V6soKo9sG5ypmt25V0mBAh3rAIs,793
2
+ pypomes_jwt/jwt_config.py,sha256=mtihd58_O00FuFXcNBKsabftG6UHu3Cj24i6cZXoskc,3096
3
+ pypomes_jwt/jwt_pomes.py,sha256=ptfxnBBtVVan0mBpHtmNto3yBBIDGp29JGeOGN8kD-8,24011
4
+ pypomes_jwt/jwt_registry.py,sha256=LZMjAquURa-oEMAyn8RbRBlOQlwg_lmcoB9NASkv39E,22137
5
+ pypomes_jwt-1.1.9.dist-info/METADATA,sha256=8udfNQmkAQabyf2fivZp_IJYYuJHd6HZt93btgIsmz0,670
6
+ pypomes_jwt-1.1.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ pypomes_jwt-1.1.9.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
8
+ pypomes_jwt-1.1.9.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- pypomes_jwt/__init__.py,sha256=NZzjWKnhjxNuoE32V6soKo9sG5ypmt25V0mBAh3rAIs,793
2
- pypomes_jwt/jwt_config.py,sha256=mtihd58_O00FuFXcNBKsabftG6UHu3Cj24i6cZXoskc,3096
3
- pypomes_jwt/jwt_pomes.py,sha256=wplcnbC1RGgfJ1VlFpRVtSXTSRfthEjqGec7S1CWHis,23858
4
- pypomes_jwt/jwt_registry.py,sha256=Zfhv5bn53UcSPuPSHns4AVMv7izrzd75HPp5eId2dck,21993
5
- pypomes_jwt-1.1.7.dist-info/METADATA,sha256=I9h4WUglqMoy7a_1uwwnG9FPi4DosV9NVZ_O1afJD7Q,632
6
- pypomes_jwt-1.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- pypomes_jwt-1.1.7.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
8
- pypomes_jwt-1.1.7.dist-info/RECORD,,