pypomes-jwt 0.4.7__py3-none-any.whl → 0.4.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/__init__.py CHANGED
@@ -5,8 +5,8 @@ from .jwt_pomes import (
5
5
  JWT_ENDPOINT_URL,
6
6
  JWT_ACCESS_MAX_AGE, JWT_REFRESH_MAX_AGE,
7
7
  JWT_HS_SECRET_KEY, JWT_RSA_PRIVATE_KEY, JWT_RSA_PUBLIC_KEY,
8
- jwt_get_token, jwt_get_token_data,
9
- jwt_get_claims, jwt_verify_request,
8
+ jwt_needed, jwt_verify_request,
9
+ jwt_get_claims, jwt_get_token, jwt_get_token_data,
10
10
  jwt_service, jwt_set_service_access, jwt_remove_service_access
11
11
  )
12
12
 
@@ -17,8 +17,8 @@ __all__ = [
17
17
  "JWT_ENDPOINT_URL",
18
18
  "JWT_ACCESS_MAX_AGE", "JWT_REFRESH_MAX_AGE",
19
19
  "JWT_HS_SECRET_KEY", "JWT_RSA_PRIVATE_KEY", "JWT_RSA_PUBLIC_KEY",
20
- "jwt_get_token", "jwt_get_token_data",
21
- "jwt_get_claims", "jwt_verify_request",
20
+ "jwt_needed", "jwt_verify_request",
21
+ "jwt_get_claims", "jwt_get_token", "jwt_get_token_data",
22
22
  "jwt_service", "jwt_set_service_access", "jwt_remove_service_access"
23
23
  ]
24
24
 
pypomes_jwt/jwt_pomes.py CHANGED
@@ -14,13 +14,13 @@ JWT_ACCESS_MAX_AGE: Final[int] = env_get_int(key=f"{APP_PREFIX}_JWT_ACCESS_MAX_A
14
14
  def_value=3600)
15
15
  JWT_REFRESH_MAX_AGE: Final[int] = env_get_int(key=f"{APP_PREFIX}_JWT_REFRESH_MAX_AGE",
16
16
  def_value=43200)
17
- JWT_HS_SECRET_KEY: Final[bytes] = env_get_bytes(key=f"{APP_PREFIX}JWT_HS_SECRET_KEY",
17
+ JWT_HS_SECRET_KEY: Final[bytes] = env_get_bytes(key=f"{APP_PREFIX}_JWT_HS_SECRET_KEY",
18
18
  def_value=token_bytes(32))
19
19
  # must point to 'jwt_service()' below
20
20
  JWT_ENDPOINT_URL: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_ENDPOINT_URL")
21
21
 
22
- __priv_key: str = env_get_str(key=f"{APP_PREFIX}JWT_RSA_PRIVATE_KEY")
23
- __pub_key: str = env_get_str(key=f"{APP_PREFIX}JWT_RSA_PUBLIC_KEY")
22
+ __priv_key: str = env_get_str(key=f"{APP_PREFIX}_JWT_RSA_PRIVATE_KEY")
23
+ __pub_key: str = env_get_str(key=f"{APP_PREFIX}_JWT_RSA_PUBLIC_KEY")
24
24
  if not __priv_key or not __pub_key:
25
25
  (__priv_key, __pub_key) = crypto_generate_rsa_keys(key_size=2048)
26
26
  JWT_RSA_PRIVATE_KEY: Final[str] = __priv_key
@@ -30,6 +30,20 @@ JWT_RSA_PUBLIC_KEY: Final[str] = __pub_key
30
30
  __jwt_data: JwtData = JwtData()
31
31
 
32
32
 
33
+ def jwt_needed(func: callable) -> callable:
34
+ """
35
+ Create a decorator to authenticate service endpoints with JWT tokens.
36
+
37
+ :param func: the function being decorated
38
+ """
39
+ # ruff: noqa: ANN003
40
+ def wrapper(*args, **kwargs) -> Response:
41
+ response: Response = jwt_verify_request(request=request) if JWT_ENDPOINT_URL else None
42
+ return response if response else func(*args, **kwargs)
43
+
44
+ return wrapper
45
+
46
+
33
47
  def jwt_set_service_access(service_url: str,
34
48
  claims: dict[str, Any],
35
49
  algorithm: Literal["HS256", "HS512", "RSA256", "RSA512"] = JWT_DEFAULT_ALGORITHM,
@@ -206,14 +220,14 @@ def jwt_verify_request(request: Request,
206
220
  status=401)
207
221
  else:
208
222
  # no, report the error
209
- result = Response(response="Authorization failed, as no JWT token was provided",
223
+ result = Response(response="Authorization failed",
210
224
  status=401)
211
225
 
212
226
  return result
213
227
 
214
228
 
215
229
  # @flask_app.route(rule="/jwt-service",
216
- # methods=["GET", "POST"])
230
+ # methods=["POST"])
217
231
  def jwt_service(service_url: str = None) -> Response:
218
232
  """
219
233
  Entry point for obtaining JWT tokens.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pypomes_jwt
3
- Version: 0.4.7
3
+ Version: 0.4.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,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: >=3.10
13
13
  Requires-Dist: pip>=24.2
14
14
  Requires-Dist: pyjwt>=2.9.0
15
- Requires-Dist: pypomes-core>=1.5.1
16
- Requires-Dist: pypomes-crypto>=0.2.9
15
+ Requires-Dist: pypomes-core>=1.5.3
16
+ Requires-Dist: pypomes-crypto>=0.3.0
17
17
  Requires-Dist: setuptools>=75.1.0
18
18
  Requires-Dist: wheel>=0.44.0
@@ -0,0 +1,7 @@
1
+ pypomes_jwt/__init__.py,sha256=1IyBb94cZjkXMibHrH_vh043b06QFh5UQ6HTYSDau28,978
2
+ pypomes_jwt/jwt_data.py,sha256=g8wnWYI7bueCIuK67eW2Uy21ALYk5RbLigUHwljjzt4,17496
3
+ pypomes_jwt/jwt_pomes.py,sha256=aPvoBhUqRCQ3yzXGab-RNvELLFlWvmZsDUNCas5VbDA,10950
4
+ pypomes_jwt-0.4.9.dist-info/METADATA,sha256=eb0MR5tHfoEGPmB9JjPOimSer5hwR5QRrU2j98Wsarg,687
5
+ pypomes_jwt-0.4.9.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
6
+ pypomes_jwt-0.4.9.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
7
+ pypomes_jwt-0.4.9.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- pypomes_jwt/__init__.py,sha256=wIbTPmnxyGFuSdawdyglNn7GVKEvPZ_57MF9HBbWclc,952
2
- pypomes_jwt/jwt_data.py,sha256=g8wnWYI7bueCIuK67eW2Uy21ALYk5RbLigUHwljjzt4,17496
3
- pypomes_jwt/jwt_pomes.py,sha256=z8T28KRL09mk3wg3weU3F7SBE6pRapB6T9zmlq9Rv1U,10538
4
- pypomes_jwt-0.4.7.dist-info/METADATA,sha256=OyqPFEIyfKvw4FtnawyNzwx81vLITmcArlS3Y8AF8VU,687
5
- pypomes_jwt-0.4.7.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
6
- pypomes_jwt-0.4.7.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
7
- pypomes_jwt-0.4.7.dist-info/RECORD,,