pypomes-jwt 0.5.4__tar.gz → 0.5.6__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,16 +1,15 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 0.5.4
3
+ Version: 0.5.6
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
7
7
  Author-email: GT Nunes <wisecoder01@gmail.com>
8
+ License-File: LICENSE
8
9
  Classifier: License :: OSI Approved :: MIT License
9
10
  Classifier: Operating System :: OS Independent
10
11
  Classifier: Programming Language :: Python :: 3
11
12
  Requires-Python: >=3.12
12
- Requires-Dist: pip>=24.3.1
13
- Requires-Dist: pyjwt>=2.10.0
14
- Requires-Dist: pypomes-core>=1.6.2
15
- Requires-Dist: setuptools>=75.5.0
16
- Requires-Dist: wheel>=0.45.0
13
+ Requires-Dist: pyjwt>=2.10.1
14
+ Requires-Dist: pyopenssl>=25.0.0
15
+ Requires-Dist: pypomes-core>=1.7.1
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "pypomes_jwt"
9
- version = "0.5.4"
9
+ version = "0.5.6"
10
10
  authors = [
11
11
  { name="GT Nunes", email="wisecoder01@gmail.com" }
12
12
  ]
@@ -19,12 +19,9 @@ classifiers = [
19
19
  "Operating System :: OS Independent"
20
20
  ]
21
21
  dependencies = [
22
- "pip>=24.3.1",
23
- "PyJWT>=2.10.0",
24
- # "PyOpenSSL>=24.2.1", - pending fixing runtime error in jwt_data.py
25
- "pypomes_core>=1.6.2",
26
- "setuptools>=75.5.0",
27
- "wheel>=0.45.0"
22
+ "PyJWT>=2.10.1",
23
+ "PyOpenSSL>=25.0.0",
24
+ "pypomes_core>=1.7.1"
28
25
  ]
29
26
 
30
27
  [project.urls]
@@ -63,14 +63,10 @@ class JwtData:
63
63
  private_key: bytes,
64
64
  public_key: bytes,
65
65
  request_timeout: float,
66
- local_provider: bool,
67
66
  logger: Logger = None) -> None:
68
67
  """
69
68
  Add to storage the parameters needed to obtain and validate JWT tokens.
70
69
 
71
- Protocol indication in *service_url* (typically *http:* or *https:*), is disregarded, to guarantee
72
- that processing herein will not be affected by in-transit protocol changes.
73
-
74
70
  Presently, the *refresh_max_age* data is not relevant, as the authorization parameters in *claims*
75
71
  (typically, an acess-key/secret-key pair), have been previously validated elsewhere.
76
72
  This situation might change in the future.
@@ -84,7 +80,6 @@ class JwtData:
84
80
  :param private_key: private key for RSA authentication
85
81
  :param public_key: public key for RSA authentication
86
82
  :param request_timeout: timeout for the requests to the service URL
87
- :param local_provider: whether 'service_url' is a local endpoint
88
83
  :param logger: optional logger
89
84
  """
90
85
  # obtain the item in storage
@@ -97,7 +92,6 @@ class JwtData:
97
92
  "algorithm": algorithm,
98
93
  "access-max-age": access_max_age,
99
94
  "request-timeout": request_timeout,
100
- "local-provider": local_provider,
101
95
  "refresh-exp": datetime.now(tz=timezone.utc) + timedelta(seconds=refresh_max_age)
102
96
  }
103
97
  if algorithm in ["HS256", "HS512"]:
@@ -176,7 +170,7 @@ class JwtData:
176
170
  :raises InvalidIssuerError: 'iss' claim does not match the expected issuer
177
171
  :raises InvalidIssuedAtError: 'iat' claim is non-numeric
178
172
  :raises MissingRequiredClaimError: a required claim is not contained in the claimset
179
- :raises RuntimeError: access data not found for the given 'service_url', or
173
+ :raises RuntimeError: access data not found for the given *service_url*, or
180
174
  the remote JWT provider failed to return a token
181
175
  """
182
176
  # declare the return variable
@@ -253,7 +247,7 @@ class JwtData:
253
247
 
254
248
  :param token: the token to be inspected for claims
255
249
  :param logger: optional logger
256
- :return: the token's claimset, or 'None' if error
250
+ :return: the token's claimset, or *None* if error
257
251
  :raises InvalidTokenError: token is not valid
258
252
  :raises ExpiredSignatureError: token has expired
259
253
  """
@@ -283,16 +277,18 @@ class JwtData:
283
277
  def retrieve_access_data(self,
284
278
  service_url: str,
285
279
  logger: Logger = None) -> dict[str, dict[str, Any]]:
280
+ # noinspection HttpUrlsUsage
286
281
  """
287
- Retrieve and return the access data in storage corresponding to *service_url*.
282
+ Retrieve and return the access data in storage corresponding to *service_url*.
288
283
 
289
- Protocol indication in *service_url* (typically *http:* or *https:*), is disregarded, to guarantee
290
- that processing herein will not be affected by in-transit protocol changes.
284
+ For the purpose of retrieving access data, Protocol indication in *service_url*
285
+ (typically, *http://* or *https://*), is disregarded. This guarantees
286
+ that processing herein will not be affected by in-transit protocol changes.
291
287
 
292
- :param service_url: the reference URL for obtaining JWT tokens
293
- :param logger: optional logger
294
- :return: the corresponding item in storage, or 'None' if not found
295
- """
288
+ :param service_url: the reference URL for obtaining JWT tokens
289
+ :param logger: optional logger
290
+ :return: the corresponding item in storage, or *None* if not found
291
+ """
296
292
  # initialize the return variable
297
293
  result: dict[str, dict[str, Any]] | None = None
298
294
 
@@ -333,7 +329,7 @@ def jwt_request_token(errors: list[str],
333
329
  :param errors: incidental errors
334
330
  :param service_url: the reference URL for obtaining JWT tokens
335
331
  :param claims: the JWT claimset, as expected by the issuing server
336
- :param timeout: request timeout, in seconds (defaults to 'None')
332
+ :param timeout: request timeout, in seconds (defaults to *None*)
337
333
  :param logger: optional logger
338
334
  """
339
335
  # initialize the return variable
@@ -58,14 +58,10 @@ def jwt_set_service_access(service_url: str,
58
58
  private_key: bytes = JWT_RSA_PRIVATE_KEY,
59
59
  public_key: bytes = JWT_RSA_PUBLIC_KEY,
60
60
  request_timeout: int = None,
61
- local_provider: bool = False,
62
61
  logger: Logger = None) -> None:
63
62
  """
64
63
  Set the data needed to obtain JWT tokens from *service_url*.
65
64
 
66
- Protocol indication in *service_url* (typically *http:* or *https:*), is disregarded, to guarantee
67
- that processing herein will not be affected by in-transit protocol changes.
68
-
69
65
  :param service_url: the reference URL
70
66
  :param claims: the JWT claimset, as key-value pairs
71
67
  :param algorithm: the authentication type
@@ -75,16 +71,14 @@ def jwt_set_service_access(service_url: str,
75
71
  :param private_key: private key for RSA authentication
76
72
  :param public_key: public key for RSA authentication
77
73
  :param request_timeout: timeout for the requests to the service URL
78
- :param local_provider: whether 'service_url' is a local endpoint
79
74
  :param logger: optional logger
80
75
  """
81
76
  # extract the extra claims
82
77
  pos: int = service_url.find("?")
83
78
  if pos > 0:
84
- if not local_provider:
85
- params: list[str] = service_url[pos+1:].split(sep="&")
86
- for param in params:
87
- claims[param.split("=")[0]] = param.split("=")[1]
79
+ params: list[str] = service_url[pos+1:].split(sep="&")
80
+ for param in params:
81
+ claims[param.split("=")[0]] = param.split("=")[1]
88
82
  service_url = service_url[:pos]
89
83
 
90
84
  # register the JWT service
@@ -97,7 +91,6 @@ def jwt_set_service_access(service_url: str,
97
91
  private_key=private_key,
98
92
  public_key=public_key,
99
93
  request_timeout=request_timeout,
100
- local_provider=local_provider,
101
94
  logger=logger)
102
95
 
103
96
 
@@ -233,11 +226,12 @@ def jwt_verify_request(request: Request,
233
226
 
234
227
  # @flask_app.route(rule="/jwt-service",
235
228
  # methods=["POST"])
236
- def jwt_service(service_url: str = None) -> Response:
229
+ def jwt_service(service_url: str = None,
230
+ service_params: dict[str, Any] = None) -> Response:
237
231
  """
238
232
  Entry point for obtaining JWT tokens.
239
233
 
240
- In order to be serviced, the invoker must send, in the body of the request,
234
+ In order to be serviced, the invoker must send, as parameter *service_params* or in the body of the request,
241
235
  a JSON containing:
242
236
  {
243
237
  "service-url": "<url>", - the JWT reference URL (if not as parameter)
@@ -252,7 +246,8 @@ def jwt_service(service_url: str = None) -> Response:
252
246
  "expires_in": <seconds-to-expiration>
253
247
  }
254
248
 
255
- :param service_url: the JWT reference URL, alternatively passed in the body's JSON
249
+ :param service_url: the JWT reference URL, alternatively passed in JSON
250
+ :param service_params: the optional JSON containing the request parameters (defaults to JSON in body)
256
251
  :return: the requested JWT token, along with its duration.
257
252
  """
258
253
  # declare the return variable
@@ -260,9 +255,10 @@ def jwt_service(service_url: str = None) -> Response:
260
255
 
261
256
  # obtain the parameters
262
257
  # noinspection PyUnusedLocal
263
- params: dict[str, Any] = {}
264
- with contextlib.suppress(Exception):
265
- params = request.get_json()
258
+ params: dict[str, Any] = service_params or {}
259
+ if not params:
260
+ with contextlib.suppress(Exception):
261
+ params = request.get_json()
266
262
 
267
263
  # validate the parameters
268
264
  valid: bool = False
File without changes
File without changes
File without changes
File without changes