pypomes-jwt 0.6.8__tar.gz → 0.7.0__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.6.8
3
+ Version: 0.7.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
@@ -12,4 +12,4 @@ Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: >=3.12
13
13
  Requires-Dist: cryptography>=44.0.1
14
14
  Requires-Dist: pyjwt>=2.10.1
15
- Requires-Dist: pypomes-core>=1.7.9
15
+ Requires-Dist: pypomes-core>=1.8.3
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "pypomes_jwt"
9
- version = "0.6.8"
9
+ version = "0.7.0"
10
10
  authors = [
11
11
  { name="GT Nunes", email="wisecoder01@gmail.com" }
12
12
  ]
@@ -21,7 +21,7 @@ classifiers = [
21
21
  dependencies = [
22
22
  "PyJWT>=2.10.1",
23
23
  "cryptography>=44.0.1",
24
- "pypomes_core>=1.7.9"
24
+ "pypomes_core>=1.8.3"
25
25
  ]
26
26
 
27
27
  [project.urls]
@@ -2,7 +2,6 @@ from .jwt_data import (
2
2
  jwt_request_token, jwt_validate_token
3
3
  )
4
4
  from .jwt_pomes import (
5
- JWT_ENDPOINT_URL,
6
5
  JWT_ACCESS_MAX_AGE, JWT_REFRESH_MAX_AGE,
7
6
  JWT_HS_SECRET_KEY, JWT_RSA_PRIVATE_KEY, JWT_RSA_PUBLIC_KEY,
8
7
  jwt_needed, jwt_verify_request, jwt_claims, jwt_token,
@@ -14,7 +13,6 @@ __all__ = [
14
13
  # jwt_data
15
14
  "jwt_request_token", "jwt_validate_token",
16
15
  # jwt_pomes
17
- "JWT_ENDPOINT_URL",
18
16
  "JWT_ACCESS_MAX_AGE", "JWT_REFRESH_MAX_AGE",
19
17
  "JWT_HS_SECRET_KEY", "JWT_RSA_PRIVATE_KEY", "JWT_RSA_PUBLIC_KEY",
20
18
  "jwt_needed", "jwt_verify_request", "jwt_claims", "jwt_token",
@@ -1,5 +1,6 @@
1
1
  import jwt
2
2
  import requests
3
+ import string
3
4
  from datetime import datetime, timezone
4
5
  from jwt.exceptions import InvalidTokenError
5
6
  from logging import Logger
@@ -214,6 +215,8 @@ class JwtData:
214
215
  # obtain a new token, if the current token has expired
215
216
  just_now: int = int(datetime.now(tz=timezone.utc).timestamp())
216
217
  if just_now > reserved_claims.get("exp"):
218
+ token_jti: str = str_random(size=32,
219
+ chars=string.ascii_letters + string.digits)
217
220
  # where is the JWT service provider ?
218
221
  if control_data.get("remote-provider"):
219
222
  # JWT service is being provided by a remote server
@@ -233,28 +236,33 @@ class JwtData:
233
236
  if reply:
234
237
  with self.access_lock:
235
238
  control_data["access-token"] = reply.get("access_token")
236
- reserved_claims["jti"] = str_random(size=16)
239
+ reserved_claims["jti"] = token_jti
237
240
  reserved_claims["iat"] = reply.get("created_in")
238
241
  reserved_claims["exp"] = reply.get("created_in") + reply.get("expires_in")
239
242
  else:
240
243
  raise RuntimeError(" - ".join(errors))
241
244
  else:
242
245
  # JWT service is being provided locally
246
+ token_iat: int = just_now
247
+ token_exp: int = just_now + control_data.get("access-max-age")
243
248
  claims: dict[str, Any] = access_data.get("public-claims").copy()
244
249
  claims.update(reserved_claims)
245
250
  claims.update(custom_claims)
251
+ claims["jti"] = token_jti
252
+ claims["iat"] = token_iat
253
+ claims["exp"] = token_exp
246
254
  # may raise an exception
247
255
  token: str = jwt.encode(payload=claims,
248
256
  key=(control_data.get("hs-secret-key") or
249
257
  control_data.get("rsa-private-key")),
250
258
  algorithm=control_data.get("algorithm"))
251
259
  with self.access_lock:
252
- reserved_claims["jti"] = str_random(size=16)
253
- reserved_claims["iat"] = just_now
254
- reserved_claims["exp"] = just_now + control_data.get("access-max-age")
260
+ reserved_claims["jti"] = token_jti
261
+ reserved_claims["iat"] = token_iat
262
+ reserved_claims["exp"] = token_exp
255
263
  control_data["access-token"] = token
256
264
 
257
- # return the token
265
+ # return the token data
258
266
  result = {
259
267
  "access_token": control_data.get("access-token"),
260
268
  "created_in": reserved_claims.get("iat"),
@@ -328,7 +336,7 @@ class JwtData:
328
336
  """
329
337
  # initialize the return variable
330
338
  result: dict[str, dict[str, Any]] | None = None
331
-
339
+
332
340
  if logger:
333
341
  target: str = f"account id '{account_id}'" if account_id else f"token '{access_token}'"
334
342
  logger.debug(f"Retrieve access data for {target}")
@@ -19,7 +19,6 @@ JWT_REFRESH_MAX_AGE: Final[int] = env_get_int(key=f"{APP_PREFIX}_JWT_REFRESH_MAX
19
19
  def_value=43200)
20
20
  JWT_HS_SECRET_KEY: Final[bytes] = env_get_bytes(key=f"{APP_PREFIX}_JWT_HS_SECRET_KEY",
21
21
  def_value=token_bytes(nbytes=32))
22
- JWT_ENDPOINT_URL: Final[str] = env_get_str(key=f"{APP_PREFIX}_JWT_ENDPOINT_URL")
23
22
 
24
23
  # obtain a RSA private/public key pair
25
24
  __priv_bytes: bytes = env_get_bytes(key=f"{APP_PREFIX}_JWT_RSA_PRIVATE_KEY")
File without changes
File without changes
File without changes
File without changes