pypomes-jwt 1.1.2__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.

@@ -1,14 +1,12 @@
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, db_setup
10
9
  from secrets import token_bytes
11
- from sys import stderr
12
10
 
13
11
 
14
12
  # recommended: allow the encode and decode keys to be generated anew when app starts
@@ -52,34 +50,14 @@ class JwtConfig(Enum):
52
50
  def_value=86400)
53
51
 
54
52
 
55
- class JwtDbConfig(Enum):
53
+ class JwtDbConfig(StrEnum):
56
54
  """
57
55
  Parameters for JWT databse connection.
58
56
  """
59
- ENGINE: str = DbEngine(env_get_str(key=f"{APP_PREFIX}_JWT_DB_ENGINE"))
60
- CLIENT: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_CLIENT") # for Oracle, only
61
- DRIVER: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_DRIVER") # for SQLServer, only
62
- NAME: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_NAME")
63
- HOST: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_HOST")
64
- PORT: int = env_get_int(key=f"{APP_PREFIX}_JWT_DB_PORT")
65
- USER: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_USER")
66
- PWD: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_PWD")
57
+ ENGINE: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_ENGINE")
67
58
  TABLE: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_TABLE")
68
59
  COL_ACCOUNT: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_ACCOUNT")
69
60
  COL_ALGORITHM: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_ALGORITHM")
70
61
  COL_DECODER: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_DECODER")
71
62
  COL_KID: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_KID")
72
63
  COL_TOKEN: str = env_get_str(key=f"{APP_PREFIX}_JWT_DB_COL_TOKEN")
73
-
74
-
75
- # define and validate the database engine
76
- # noinspection PyTypeChecker
77
- if not db_setup(engine=JwtDbConfig.ENGINE.value,
78
- db_name=JwtDbConfig.NAME.value,
79
- db_user=JwtDbConfig.USER.value,
80
- db_pwd=JwtDbConfig.PWD.value,
81
- db_host=JwtDbConfig.HOST.value,
82
- db_port=JwtDbConfig.PORT.value,
83
- db_client=JwtDbConfig.CLIENT.value,
84
- db_driver=JwtDbConfig.DRIVER.value):
85
- stderr.write("Invalid database parameters\n")
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, db_rollback, db_select, db_delete
8
+ DbEngine, db_connect, db_commit,
9
+ db_rollback, db_select, db_delete
9
10
  )
10
11
  from typing import Any
11
12
 
@@ -177,14 +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.value: int(token_kid[1:])}
181
+ where_data: dict[str, Any] = {JwtDbConfig.COL_KID: int(token_kid[1:])}
181
182
  if account_id:
182
- where_data[JwtDbConfig.COL_ACCOUNT.value] = account_id
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.value}, "
185
- f"{JwtDbConfig.COL_DECODER.value} "
186
- f"FROM {JwtDbConfig.TABLE.value}",
185
+ sel_stmt=f"SELECT {JwtDbConfig.COL_ALGORITHM}, "
186
+ f"{JwtDbConfig.COL_DECODER} "
187
+ f"FROM {JwtDbConfig.TABLE}",
187
188
  where_data=where_data,
189
+ engine=DbEngine(JwtDbConfig.ENGINE),
188
190
  logger=logger)
189
191
  if recs:
190
192
  token_alg = recs[0][0]
@@ -278,11 +280,12 @@ def jwt_revoke_token(errors: list[str] | None,
278
280
  op_errors.append("Invalid token")
279
281
  else:
280
282
  db_delete(errors=op_errors,
281
- delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE.value}",
283
+ delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
282
284
  where_data={
283
- JwtDbConfig.COL_KID.value: int(token_kid[1:]),
284
- JwtDbConfig.COL_ACCOUNT.value: account_id
285
+ JwtDbConfig.COL_KID: int(token_kid[1:]),
286
+ JwtDbConfig.COL_ACCOUNT: account_id
285
287
  },
288
+ engine=DbEngine(JwtDbConfig.ENGINE),
286
289
  logger=logger)
287
290
  if op_errors:
288
291
  if logger:
@@ -448,15 +451,17 @@ def jwt_refresh_tokens(errors: list[str] | None,
448
451
  # start the database transaction
449
452
  db_conn: Any = db_connect(errors=op_errors,
450
453
  autocommit=False,
454
+ engine=DbEngine(JwtDbConfig.ENGINE),
451
455
  logger=logger)
452
456
  if db_conn:
453
457
  # delete current refresh token
454
458
  db_delete(errors=op_errors,
455
- delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE.value}",
459
+ delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
456
460
  where_data={
457
- JwtDbConfig.COL_KID.value: int(token_kid[1:]),
458
- JwtDbConfig.COL_ACCOUNT.value: account_id
461
+ JwtDbConfig.COL_KID: int(token_kid[1:]),
462
+ JwtDbConfig.COL_ACCOUNT: account_id
459
463
  },
464
+ engine=DbEngine(JwtDbConfig.ENGINE),
460
465
  connection=db_conn,
461
466
  committable=False,
462
467
  logger=logger)
@@ -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,8 +139,9 @@ class JwtRegistry:
139
139
 
140
140
  # remove from database
141
141
  db_delete(errors=None,
142
- delete_stmt=f"DELETE FROM {JwtDbConfig.value}",
143
- where_data={JwtDbConfig.COL_ACCOUNT.value: account_id},
142
+ delete_stmt=f"DELETE FROM {JwtDbConfig}",
143
+ where_data={JwtDbConfig.COL_ACCOUNT: account_id},
144
+ engine=DbEngine(JwtDbConfig.ENGINE),
144
145
  logger=logger)
145
146
  if logger:
146
147
  if account_data:
@@ -282,6 +283,7 @@ class JwtRegistry:
282
283
  # make sure to have a database connection
283
284
  curr_conn: Any = db_conn or db_connect(errors=errors,
284
285
  autocommit=False,
286
+ engine=DbEngine(JwtDbConfig.ENGINE),
285
287
  logger=logger)
286
288
  if curr_conn:
287
289
  # persist the candidate token (may raise an exception)
@@ -296,9 +298,10 @@ class JwtRegistry:
296
298
  headers={"kid": f"R{token_id}"})
297
299
  # persist it
298
300
  db_update(errors=errors,
299
- update_stmt=f"UPDATE {JwtDbConfig.TABLE.value}",
300
- update_data={JwtDbConfig.COL_TOKEN.value: refresh_token},
301
- where_data={JwtDbConfig.COL_KID.value: token_id},
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),
302
305
  connection=curr_conn,
303
306
  committable=False,
304
307
  logger=logger)
@@ -379,9 +382,10 @@ def _jwt_persist_token(account_id: str,
379
382
  # noinspection PyTypeChecker
380
383
  recs: list[tuple[int, str, str, str]] = \
381
384
  db_select(errors=errors,
382
- sel_stmt=f"SELECT {JwtDbConfig.COL_KID.value}, {JwtDbConfig.COL_TOKEN.value} "
383
- f"FROM {JwtDbConfig.TABLE.value}",
384
- where_data={JwtDbConfig.COL_ACCOUNT.value: account_id},
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),
385
389
  connection=db_conn,
386
390
  committable=False,
387
391
  logger=logger)
@@ -422,8 +426,9 @@ def _jwt_persist_token(account_id: str,
422
426
  # remove expired tokens from persistence
423
427
  if expired:
424
428
  db_delete(errors=errors,
425
- delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE.value}",
426
- where_data={JwtDbConfig.COL_KID.value: expired},
429
+ delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
430
+ where_data={JwtDbConfig.COL_KID: expired},
431
+ engine=DbEngine(JwtDbConfig.ENGINE),
427
432
  connection=db_conn,
428
433
  committable=False,
429
434
  logger=logger)
@@ -436,8 +441,9 @@ def _jwt_persist_token(account_id: str,
436
441
  if 0 < JwtConfig.ACCOUNT_LIMIT.value <= len(recs) - len(expired):
437
442
  # delete the oldest token to make way for the new one
438
443
  db_delete(errors=errors,
439
- delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE.value}",
440
- where_data={JwtDbConfig.COL_KID.value: oldest_id},
444
+ delete_stmt=f"DELETE FROM {JwtDbConfig.TABLE}",
445
+ where_data={JwtDbConfig.COL_KID: oldest_id},
446
+ engine=DbEngine(JwtDbConfig.ENGINE),
441
447
  connection=db_conn,
442
448
  committable=False,
443
449
  logger=logger)
@@ -448,13 +454,14 @@ def _jwt_persist_token(account_id: str,
448
454
  f"'{account_id}' removed from storage")
449
455
  # persist token
450
456
  db_insert(errors=errors,
451
- insert_stmt=f"INSERT INTO {JwtDbConfig.TABLE.value}",
457
+ insert_stmt=f"INSERT INTO {JwtDbConfig.TABLE}",
452
458
  insert_data={
453
- JwtDbConfig.COL_ACCOUNT.value: account_id,
454
- JwtDbConfig.COL_TOKEN.value: jwt_token,
455
- JwtDbConfig.COL_ALGORITHM.value: JwtConfig.DEFAULT_ALGORITHM.value,
456
- JwtDbConfig.COL_DECODER.value: urlsafe_b64encode(s=JwtConfig.DECODING_KEY.value).decode()
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()
457
463
  },
464
+ engine=DbEngine(JwtDbConfig.ENGINE),
458
465
  connection=db_conn,
459
466
  committable=False,
460
467
  logger=logger)
@@ -465,14 +472,15 @@ def _jwt_persist_token(account_id: str,
465
472
  # HAZARD: JWT_DB_COL_TOKEN's column type might prevent it for being used in a WHERE clause
466
473
  where_clause: str | None = None
467
474
  if existing_ids:
468
- where_clause = f"{JwtDbConfig.COL_KID.value} NOT IN {existing_ids}"
475
+ where_clause = f"{JwtDbConfig.COL_KID} NOT IN {existing_ids}"
469
476
  where_clause = where_clause.replace("[", "(", 1).replace("]", ")", 1)
470
477
  reply: list[tuple[int]] = db_select(errors=errors,
471
- sel_stmt=f"SELECT {JwtDbConfig.COL_KID.value} "
472
- f"FROM {JwtDbConfig.TABLE.value}",
478
+ sel_stmt=f"SELECT {JwtDbConfig.COL_KID} "
479
+ f"FROM {JwtDbConfig.TABLE}",
473
480
  where_clause=where_clause,
474
- where_data={JwtDbConfig.COL_ACCOUNT.value: account_id},
481
+ where_data={JwtDbConfig.COL_ACCOUNT: account_id},
475
482
  require_count=1,
483
+ engine=DbEngine(JwtDbConfig.ENGINE),
476
484
  connection=db_conn,
477
485
  committable=False,
478
486
  logger=logger)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 1.1.2
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>=1.9.8
16
- Requires-Dist: pypomes-db>=2.0.9
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=GBkt8ISgcRYMh1FuTxUBWiKFACHHz-67mejSaPdiEsc,4172
3
- pypomes_jwt/jwt_pomes.py,sha256=e-E-T_hkk_FNmpsndee8AhcuUWR775SIxo4YBqjCFDA,23290
4
- pypomes_jwt/jwt_registry.py,sha256=7eWFEdzCMXjdxwR8nO_rqAeZ6SDf-WAEksDlfLPM_o4,23212
5
- pypomes_jwt-1.1.2.dist-info/METADATA,sha256=nIpMJ0AN-R9XZNsbEBVAu9ueTCOSQj3LxDgAOQrLKRU,632
6
- pypomes_jwt-1.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- pypomes_jwt-1.1.2.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
8
- pypomes_jwt-1.1.2.dist-info/RECORD,,