pypomes-jwt 0.9.2__tar.gz → 0.9.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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 0.9.2
3
+ Version: 0.9.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
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "pypomes_jwt"
9
- version = "0.9.2"
9
+ version = "0.9.3"
10
10
  authors = [
11
11
  { name="GT Nunes", email="wisecoder01@gmail.com" }
12
12
  ]
@@ -9,8 +9,8 @@ from .jwt_constants import (
9
9
  from .jwt_pomes import (
10
10
  jwt_needed, jwt_verify_request,
11
11
  jwt_assert_account, jwt_set_account, jwt_remove_account,
12
- jwt_issue_token, jwt_issue_tokens, jwt_get_claims,
13
- jwt_validate_token, jwt_revoke_token
12
+ jwt_issue_token, jwt_issue_tokens, jwt_refresh_tokens,
13
+ jwt_get_claims, jwt_validate_token, jwt_revoke_token
14
14
  )
15
15
 
16
16
  __all__ = [
@@ -24,8 +24,8 @@ __all__ = [
24
24
  # jwt_pomes
25
25
  "jwt_needed", "jwt_verify_request",
26
26
  "jwt_assert_account", "jwt_set_account", "jwt_remove_account",
27
- "jwt_issue_token", "jwt_issue_tokens", "jwt_get_claims",
28
- "jwt_validate_token", "jwt_revoke_token"
27
+ "jwt_issue_token", "jwt_issue_tokens", "jwt_refresh_tokens",
28
+ "jwt_get_claims", "jwt_validate_token", "jwt_revoke_token"
29
29
  ]
30
30
 
31
31
  from importlib.metadata import version
@@ -263,7 +263,7 @@ def jwt_revoke_token(errors: list[str] | None,
263
263
 
264
264
  :param errors: incidental error messages
265
265
  :param account_id: the account identification
266
- :param refresh_token: the token to be revolked
266
+ :param refresh_token: the token to be revoked
267
267
  :param logger: optional logger
268
268
  :return: *True* if operation could be performed, *False* otherwise
269
269
  """
@@ -327,7 +327,7 @@ def jwt_issue_token(errors: list[str] | None,
327
327
  result: str | None = None
328
328
 
329
329
  if logger:
330
- logger.debug(msg=f"Issue a JWT token for '{account_id}'")
330
+ logger.debug(msg=f"Issuing a JWT token for '{account_id}'")
331
331
  op_errors: list[str] = []
332
332
 
333
333
  try:
@@ -355,7 +355,6 @@ def jwt_issue_token(errors: list[str] | None,
355
355
  def jwt_issue_tokens(errors: list[str] | None,
356
356
  account_id: str,
357
357
  account_claims: dict[str, Any] = None,
358
- refresh_token: str = None,
359
358
  logger: Logger = None) -> dict[str, Any]:
360
359
  """
361
360
  Issue the JWT tokens associated with *account_id*, for access and refresh operations.
@@ -376,7 +375,6 @@ def jwt_issue_tokens(errors: list[str] | None,
376
375
  :param errors: incidental error messages
377
376
  :param account_id: the account identification
378
377
  :param account_claims: if provided, may supercede registered claims
379
- :param refresh_token: if provided, defines a token refresh operation
380
378
  :param logger: optional logger
381
379
  :return: the JWT token data, or *None* if error
382
380
  """
@@ -384,34 +382,82 @@ def jwt_issue_tokens(errors: list[str] | None,
384
382
  result: dict[str, Any] | None = None
385
383
 
386
384
  if logger:
387
- logger.debug(msg=f"Return JWT token data for '{account_id}'")
385
+ logger.debug(msg=f"Issuing a pair of JWT tokens for '{account_id}'")
386
+ op_errors: list[str] = []
387
+
388
+ try:
389
+ result = __jwt_registry.issue_tokens(account_id=account_id,
390
+ account_claims=account_claims,
391
+ logger=logger)
392
+ if logger:
393
+ logger.debug(msg=f"Token data is '{result}'")
394
+ except Exception as e:
395
+ # token issuing failed
396
+ op_errors.append(str(e))
397
+
398
+ if op_errors:
399
+ if logger:
400
+ logger.error("; ".join(op_errors))
401
+ if isinstance(errors, list):
402
+ errors.extend(op_errors)
403
+
404
+ return result
405
+
406
+
407
+ def jwt_refresh_tokens(errors: list[str] | None,
408
+ account_id: str,
409
+ refresh_token: str = None,
410
+ logger: Logger = None) -> dict[str, Any]:
411
+ """
412
+ Issue the JWT tokens associated with *account_id*, for access and refresh operations.
413
+
414
+ The claims in *refresh-token* are used on issuing the new tokens.
415
+
416
+ Structure of the return data:
417
+ {
418
+ "access_token": <jwt-token>,
419
+ "created_in": <timestamp>,
420
+ "expires_in": <seconds-to-expiration>,
421
+ "refresh_token": <jwt-token>
422
+ }
423
+
424
+ :param errors: incidental error messages
425
+ :param account_id: the account identification
426
+ :param refresh_token: the base refresh token
427
+ :param logger: optional logger
428
+ :return: the JWT token data, or *None* if error
429
+ """
430
+ # inicialize the return variable
431
+ result: dict[str, Any] | None = None
432
+
433
+ if logger:
434
+ logger.debug(msg=f"Refreshing a pair of JWT tokens for '{account_id}'")
388
435
  op_errors: list[str] = []
389
436
 
390
437
  # verify whether this refresh token is legitimate
391
438
  if refresh_token:
392
- account_claims = (jwt_validate_token(errors=op_errors,
393
- token=refresh_token,
394
- natures=["R"],
395
- account_id=account_id,
396
- logger=logger) or {}).get("payload")
397
- if account_claims:
439
+ account_claims: dict[str, Any] = (jwt_validate_token(errors=op_errors,
440
+ token=refresh_token,
441
+ natures=["R"],
442
+ account_id=account_id,
443
+ logger=logger) or {}).get("payload")
444
+ # revoke current refresh token
445
+ if account_claims and jwt_revoke_token(errors=errors,
446
+ account_id=account_id,
447
+ refresh_token=refresh_token,
448
+ logger=logger):
398
449
  account_claims.pop("exp", None)
399
450
  account_claims.pop("iat", None)
400
451
  account_claims.pop("iss", None)
401
452
  account_claims.pop("jti", None)
402
453
  account_claims.pop("nbt", None)
403
454
  account_claims.pop("sub", None)
404
-
405
- if not op_errors:
406
- try:
407
- result = __jwt_registry.issue_tokens(account_id=account_id,
408
- account_claims=account_claims,
409
- logger=logger)
410
- if logger:
411
- logger.debug(msg=f"Token data is '{result}'")
412
- except Exception as e:
413
- # token issuing failed
414
- op_errors.append(str(e))
455
+ # issue tokens
456
+ result = jwt_issue_tokens(errors=errors,
457
+ account_id=account_id,
458
+ account_claims=account_claims)
459
+ else:
460
+ op_errors.append("Refresh token was not provided")
415
461
 
416
462
  if op_errors:
417
463
  if logger:
File without changes
File without changes
File without changes
File without changes