pypomes-jwt 0.9.4__py3-none-any.whl → 0.9.5__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
@@ -61,7 +61,7 @@ def jwt_verify_request(request: Request,
61
61
  logger.debug(msg="Bearer token was retrieved")
62
62
  errors: list[str] = []
63
63
  jwt_validate_token(errors=errors,
64
- natures=["A"],
64
+ nature="A",
65
65
  token=token)
66
66
  if errors:
67
67
  err_msg = "; ".join(errors)
@@ -151,7 +151,7 @@ def jwt_remove_account(account_id: str,
151
151
 
152
152
  def jwt_validate_token(errors: list[str] | None,
153
153
  token: str,
154
- natures: list[str] = None,
154
+ nature: str = None,
155
155
  account_id: str = None,
156
156
  logger: Logger = None) -> dict[str, Any] | None:
157
157
  """
@@ -164,7 +164,7 @@ def jwt_validate_token(errors: list[str] | None,
164
164
 
165
165
  :param errors: incidental error messages
166
166
  :param token: the token to be validated
167
- :param natures: one or more prefixes identifying the nature of locally issued tokens
167
+ :param nature: prefix identifying the nature of locally issued tokens
168
168
  :param account_id: optionally, validate the token's account owner
169
169
  :param logger: optional logger
170
170
  :return: The token's claims (header and payload) if if is valid, *None* otherwise
@@ -182,9 +182,10 @@ def jwt_validate_token(errors: list[str] | None,
182
182
  op_errors: list[str] = []
183
183
 
184
184
  # retrieve token data from database
185
- if natures and not (token_kid and token_kid[0:1] in natures):
185
+ if nature and not (token_kid and token_kid[0:1] == nature):
186
186
  op_errors.append("Invalid token")
187
- elif token_kid and len(token_kid) > 1 and token_kid[0:1].isupper() and token[1:].isdigit():
187
+ elif token_kid and len(token_kid) > 1 and \
188
+ token_kid[0:1] in ["A", "R"] and token[1:].isdigit():
188
189
  # token was likely issued locally
189
190
  where_data: dict[str, Any] = {JWT_DB_COL_KID: int(token_kid[1:])}
190
191
  if account_id:
@@ -270,18 +271,20 @@ def jwt_revoke_token(errors: list[str] | None,
270
271
  op_errors: list[str] = []
271
272
  token_claims: dict[str, Any] = jwt_validate_token(errors=op_errors,
272
273
  token=refresh_token,
273
- natures=["A", "R"],
274
274
  account_id=account_id,
275
275
  logger=logger)
276
276
  if not op_errors:
277
277
  token_kid: str = token_claims["header"].get("kid")
278
- db_delete(errors=op_errors,
279
- delete_stmt=f"DELETE FROM {JWT_DB_TABLE}",
280
- where_data={
281
- JWT_DB_COL_KID: int(token_kid[1:]),
282
- JWT_DB_COL_ACCOUNT: account_id
283
- },
284
- logger=logger)
278
+ if token_kid[0:1] not in ["A", "R"]:
279
+ op_errors.append("Invalid token")
280
+ else:
281
+ db_delete(errors=op_errors,
282
+ delete_stmt=f"DELETE FROM {JWT_DB_TABLE}",
283
+ where_data={
284
+ JWT_DB_COL_KID: int(token_kid[1:]),
285
+ JWT_DB_COL_ACCOUNT: account_id
286
+ },
287
+ logger=logger)
285
288
  if op_errors:
286
289
  if logger:
287
290
  logger.error(msg="; ".join(op_errors))
@@ -351,12 +354,10 @@ def jwt_issue_tokens(errors: list[str] | None,
351
354
  account_claims: dict[str, Any] = None,
352
355
  logger: Logger = None) -> dict[str, Any]:
353
356
  """
354
- Issue the JWT tokens associated with *account_id*, for access and refresh operations.
357
+ Issue the JWT token pair associated with *account_id*, for access and refresh operations.
355
358
 
356
- If *refresh_token* is provided, its claims are used on issuing the new tokens, and
357
- claims in *account_claims*, if any, are ignored. Furthermore, these claims are ignored,
358
- if provided in *account_claims*: *iat*, *iss*, *exp*, *jti*, *nbf*, and *sub*.
359
- Other claims specified therein may supercede registered account-related claims.
359
+ These claims are ignored, if provided in *account_claims*: *iat*, *iss*, *exp*, *jti*, *nbf*, and *sub*.
360
+ Other claims specified therein may supercede currently registered account-related claims.
360
361
 
361
362
  Structure of the return data:
362
363
  {
@@ -368,7 +369,7 @@ def jwt_issue_tokens(errors: list[str] | None,
368
369
 
369
370
  :param errors: incidental error messages
370
371
  :param account_id: the account identification
371
- :param account_claims: if provided, may supercede registered claims
372
+ :param account_claims: if provided, may supercede currently registered account-related claims
372
373
  :param logger: optional logger
373
374
  :return: the JWT token data, or *None* if error
374
375
  """
@@ -376,7 +377,7 @@ def jwt_issue_tokens(errors: list[str] | None,
376
377
  result: dict[str, Any] | None = None
377
378
 
378
379
  if logger:
379
- logger.debug(msg=f"Issuing a pair of JWT tokens for '{account_id}'")
380
+ logger.debug(msg=f"Issuing a JWT token pair for '{account_id}'")
380
381
  op_errors: list[str] = []
381
382
 
382
383
  try:
@@ -400,10 +401,10 @@ def jwt_issue_tokens(errors: list[str] | None,
400
401
 
401
402
  def jwt_refresh_tokens(errors: list[str] | None,
402
403
  account_id: str,
403
- refresh_token: str = None,
404
+ refresh_token: str,
404
405
  logger: Logger = None) -> dict[str, Any]:
405
406
  """
406
- Issue the JWT tokens associated with *account_id*, for access and refresh operations.
407
+ Refresh the JWT token pair associated with *account_id*, for access and refresh operations.
407
408
 
408
409
  The claims in *refresh-token* are used on issuing the new tokens.
409
410
 
@@ -425,14 +426,14 @@ def jwt_refresh_tokens(errors: list[str] | None,
425
426
  result: dict[str, Any] | None = None
426
427
 
427
428
  if logger:
428
- logger.debug(msg=f"Refreshing a pair of JWT tokens for '{account_id}'")
429
+ logger.debug(msg=f"Refreshing a JWT token pair for '{account_id}'")
429
430
  op_errors: list[str] = []
430
431
 
431
432
  # verify whether this refresh token is legitimate
432
433
  if refresh_token:
433
434
  account_claims: dict[str, Any] = (jwt_validate_token(errors=op_errors,
434
435
  token=refresh_token,
435
- natures=["R"],
436
+ nature="R",
436
437
  account_id=account_id,
437
438
  logger=logger) or {}).get("payload")
438
439
  # revoke current refresh token
@@ -440,12 +441,6 @@ def jwt_refresh_tokens(errors: list[str] | None,
440
441
  account_id=account_id,
441
442
  refresh_token=refresh_token,
442
443
  logger=logger):
443
- account_claims.pop("exp", None)
444
- account_claims.pop("iat", None)
445
- account_claims.pop("iss", None)
446
- account_claims.pop("jti", None)
447
- account_claims.pop("nbt", None)
448
- account_claims.pop("sub", None)
449
444
  # issue tokens
450
445
  result = jwt_issue_tokens(errors=errors,
451
446
  account_id=account_id,
@@ -238,7 +238,7 @@ class JwtRegistry:
238
238
  account_claims: dict[str, Any] = None,
239
239
  logger: Logger = None) -> dict[str, Any]:
240
240
  """
241
- Issue and return the JWT access and refresh tokens for *account_id*.
241
+ Issue and return a JWT token pair associated with *account_id*.
242
242
 
243
243
  These claims are ignored, if specified in *account_claims*: *iat*, *iss*, *exp*, *jti*, *nbf*, and *sub*.
244
244
  Other claims specified therein may supercede registered account-related claims.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 0.9.4
3
+ Version: 0.9.5
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
@@ -0,0 +1,8 @@
1
+ pypomes_jwt/__init__.py,sha256=t6TzpvttDuLMaKSGuBicOf9cZU4Y0N9mtby3ThS4lt8,1398
2
+ pypomes_jwt/jwt_constants.py,sha256=IQV39AiZKGuU8XxZBgJ-KJZQZ_mmnxyOnRZeuxlqDRk,4045
3
+ pypomes_jwt/jwt_pomes.py,sha256=ZQ-x9nJqRqSfLXcoN0crh4a-BhT1MNOMvZkFTsaQsuE,21069
4
+ pypomes_jwt/jwt_registry.py,sha256=27Z0wbDCNcy_Klm50dGhJ1ZVYznj0SNdMjzHVT_Uzzo,25588
5
+ pypomes_jwt-0.9.5.dist-info/METADATA,sha256=IZT48rR9ftHECxA8Xy0HhhkHLX1rUQk-rDsdtMgb8TI,632
6
+ pypomes_jwt-0.9.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ pypomes_jwt-0.9.5.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
8
+ pypomes_jwt-0.9.5.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- pypomes_jwt/__init__.py,sha256=t6TzpvttDuLMaKSGuBicOf9cZU4Y0N9mtby3ThS4lt8,1398
2
- pypomes_jwt/jwt_constants.py,sha256=IQV39AiZKGuU8XxZBgJ-KJZQZ_mmnxyOnRZeuxlqDRk,4045
3
- pypomes_jwt/jwt_pomes.py,sha256=0bnKkq-wBHqBoQYmHGxWamOHmehLqHSNUs08NUJHT6Q,21413
4
- pypomes_jwt/jwt_registry.py,sha256=GbfDwMDUMjX8qJahMnOQ0FQUnxyiEuODrn6E-wIkDnk,25593
5
- pypomes_jwt-0.9.4.dist-info/METADATA,sha256=bCKCOvGx0C7n89t3eO9U7h9g0rb0YoEyZB550E-L874,632
6
- pypomes_jwt-0.9.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- pypomes_jwt-0.9.4.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
8
- pypomes_jwt-0.9.4.dist-info/RECORD,,