pypomes-jwt 0.5.8__py3-none-any.whl → 0.6.0__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_data.py CHANGED
@@ -418,7 +418,9 @@ def jwt_validate_token(token: str,
418
418
  :raises InvalidSignatureError: signature does not match the one provided as part of the token
419
419
  """
420
420
  if logger:
421
- logger.debug(msg=f"Verify request for JWT token '{token}'")
421
+ logger.debug(msg=f"Validate JWT token '{token}'")
422
422
  jwt.decode(jwt=token,
423
423
  key=key,
424
424
  algorithms=[algorithm])
425
+ if logger:
426
+ logger.debug(msg=f"Token '{token}' is valid")
pypomes_jwt/jwt_pomes.py CHANGED
@@ -1,7 +1,10 @@
1
1
  import contextlib
2
+ from cryptography.hazmat.backends import default_backend
3
+ from cryptography.hazmat.primitives import serialization
4
+ from cryptography.hazmat.primitives.asymmetric import rsa
5
+ from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey
2
6
  from flask import Request, Response, request, jsonify
3
7
  from logging import Logger
4
- # from OpenSSL import crypto
5
8
  from pypomes_core import APP_PREFIX, env_get_str, env_get_bytes, env_get_int
6
9
  from secrets import token_bytes
7
10
  from typing import Any, Final, Literal
@@ -19,14 +22,21 @@ JWT_HS_SECRET_KEY: Final[bytes] = env_get_bytes(key=f"{APP_PREFIX}_JWT_HS_SECRET
19
22
  # must invoke 'jwt_service()' below
20
23
  JWT_ENDPOINT_URL: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_ENDPOINT_URL")
21
24
 
22
- __priv_key: bytes = env_get_bytes(key=f"{APP_PREFIX}_JWT_RSA_PRIVATE_KEY")
23
- __pub_key: bytes = env_get_bytes(key=f"{APP_PREFIX}_JWT_RSA_PUBLIC_KEY")
24
- # if not __priv_key or not __pub_key:
25
- # pk = crypto.PKey()
26
- # __priv_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pk)
27
- # __pub_key = crypto.dump_publickey(crypto.FILETYPE_PEM, pk)
28
- JWT_RSA_PRIVATE_KEY: Final[bytes] = __priv_key
29
- JWT_RSA_PUBLIC_KEY: Final[bytes] = __pub_key
25
+ # obtain a RSA private/public key pair
26
+ __priv_bytes: bytes = env_get_bytes(key=f"{APP_PREFIX}_JWT_RSA_PRIVATE_KEY")
27
+ __pub_bytes: bytes = env_get_bytes(key=f"{APP_PREFIX}_JWT_RSA_PUBLIC_KEY")
28
+ if not __priv_bytes or not __pub_bytes:
29
+ __priv_key: RSAPrivateKey = rsa.generate_private_key(public_exponent=65537,
30
+ key_size=2058,
31
+ backend=default_backend())
32
+ __priv_bytes = __priv_key.private_bytes(encoding=serialization.Encoding.PEM,
33
+ format=serialization.PrivateFormat.TraditionalOpenSSL,
34
+ encryption_algorithm=serialization.NoEncryption())
35
+ __pub_key: RSAPublicKey = __priv_key.public_key()
36
+ __pub_bytes = __pub_key.public_bytes(encoding=serialization.Encoding.PEM,
37
+ format=serialization.PublicFormat.SubjectPublicKeyInfo)
38
+ JWT_RSA_PRIVATE_KEY: Final[bytes] = __priv_bytes
39
+ JWT_RSA_PUBLIC_KEY: Final[bytes] = __pub_bytes
30
40
 
31
41
  # the JWT data object
32
42
  __jwt_data: JwtData = JwtData()
@@ -76,7 +86,7 @@ def jwt_set_service_access(reference_url: str,
76
86
  :param logger: optional logger
77
87
  """
78
88
  if logger:
79
- logger.debug(msg=f"Register access data for reference URL '{reference_url}'")
89
+ logger.debug(msg=f"Register access data for '{reference_url}'")
80
90
  # extract the extra claims
81
91
  pos: int = reference_url.find("?")
82
92
  if pos > 0:
@@ -109,7 +119,7 @@ def jwt_remove_service_access(reference_url: str,
109
119
  :param logger: optional logger
110
120
  """
111
121
  if logger:
112
- logger.debug(msg=f"Remove access data for reference URL '{reference_url}'")
122
+ logger.debug(msg=f"Remove access data for '{reference_url}'")
113
123
 
114
124
  __jwt_data.remove_access_data(reference_url=reference_url,
115
125
  logger=logger)
@@ -130,7 +140,7 @@ def jwt_get_token(errors: list[str],
130
140
  result: str | None = None
131
141
 
132
142
  if logger:
133
- logger.debug(msg=f"Obtain a JWT token for reference URL '{reference_url}'")
143
+ logger.debug(msg=f"Obtain a JWT token for '{reference_url}'")
134
144
 
135
145
  try:
136
146
  token_data: dict[str, Any] = __jwt_data.get_token_data(reference_url=reference_url,
@@ -167,7 +177,7 @@ def jwt_get_token_data(errors: list[str],
167
177
  result: dict[str, Any] | None = None
168
178
 
169
179
  if logger:
170
- logger.debug(msg=f"Retrieve JWT token data for reference URL '{reference_url}'")
180
+ logger.debug(msg=f"Retrieve JWT token data for '{reference_url}'")
171
181
  try:
172
182
  result = __jwt_data.get_token_data(reference_url=reference_url,
173
183
  logger=logger)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 0.5.8
3
+ Version: 0.6.0
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
@@ -10,6 +10,6 @@ Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: >=3.12
13
+ Requires-Dist: cryptography>=44.0.0
13
14
  Requires-Dist: pyjwt>=2.10.1
14
- Requires-Dist: pyopenssl>=25.0.0
15
15
  Requires-Dist: pypomes-core>=1.7.1
@@ -0,0 +1,7 @@
1
+ pypomes_jwt/__init__.py,sha256=1IyBb94cZjkXMibHrH_vh043b06QFh5UQ6HTYSDau28,978
2
+ pypomes_jwt/jwt_data.py,sha256=z-cQjhWDAtYs67CCxaPm-CeJFOF__OyupFIz0jWugiI,19001
3
+ pypomes_jwt/jwt_pomes.py,sha256=kcoQDepMdeeriCe3oCkQfNctaNyDcIHmhY6uV5Ll6B8,13594
4
+ pypomes_jwt-0.6.0.dist-info/METADATA,sha256=jECOxmllsm_0b4SxSQ_CV0SLTqR0PrIxUQXV9nk1Y-0,599
5
+ pypomes_jwt-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ pypomes_jwt-0.6.0.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
7
+ pypomes_jwt-0.6.0.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- pypomes_jwt/__init__.py,sha256=1IyBb94cZjkXMibHrH_vh043b06QFh5UQ6HTYSDau28,978
2
- pypomes_jwt/jwt_data.py,sha256=6Y3a_GoiLy9zailSmYvN144Sbx1Rffrj_x3Hhp13iUQ,18940
3
- pypomes_jwt/jwt_pomes.py,sha256=YBpGjIKd_ueo-eXRfob7ibS2EkcPwWAwHLdBTaud-FY,12779
4
- pypomes_jwt-0.5.8.dist-info/METADATA,sha256=IN4HibJ0R7zJLgcrjh7qA8gOFDdGTKKY3c9HUBUrrVo,596
5
- pypomes_jwt-0.5.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
- pypomes_jwt-0.5.8.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
7
- pypomes_jwt-0.5.8.dist-info/RECORD,,