pypomes-jwt 0.6.4__py3-none-any.whl → 0.6.5__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
@@ -39,14 +39,14 @@ class JwtData:
39
39
  # "aud": <string> # audience
40
40
  # "nbt": <timestamp> # not before time
41
41
  },
42
- "public-claims": {
42
+ "public-claims": { # public claims (may be empty)
43
43
  "birthdate": <string>, # subject's birth date
44
44
  "email": <string>, # subject's email
45
45
  "gender": <string>, # subject's gender
46
46
  "name": <string>, # subject's name
47
47
  "roles": <List[str]> # subject roles
48
48
  },
49
- "custom-claims": { # custom claims
49
+ "custom-claims": { # custom claims (may be empty)
50
50
  "<custom-claim-key-1>": "<custom-claim-value-1>",
51
51
  ...
52
52
  "<custom-claim-key-n>": "<custom-claim-value-n>"
@@ -166,6 +166,7 @@ class JwtData:
166
166
 
167
167
  def get_token_data(self,
168
168
  account_id: str,
169
+ superceding_claims: dict[str, Any] = None,
169
170
  logger: Logger = None) -> dict[str, Any]:
170
171
  """
171
172
  Obtain and return the JWT token for *account_id*, along with its duration.
@@ -178,6 +179,7 @@ class JwtData:
178
179
  }
179
180
 
180
181
  :param account_id: the account identification
182
+ :param superceding_claims: if provided, may supercede registered custom claims
181
183
  :param logger: optional logger
182
184
  :return: the JWT token data, or *None* if error
183
185
  :raises InvalidTokenError: token is invalid
@@ -205,9 +207,12 @@ class JwtData:
205
207
  control_data: dict[str, Any] = item_data.get("control-data")
206
208
  reserved_claims: dict[str, Any] = item_data.get("reserved-claims")
207
209
  custom_claims: dict[str, Any] = item_data.get("custom-claims")
208
- just_now: int = int(datetime.now(tz=timezone.utc).timestamp())
210
+ if superceding_claims:
211
+ custom_claims = custom_claims.copy()
212
+ custom_claims.update(m=superceding_claims)
209
213
 
210
214
  # obtain a new token, if the current token has expired
215
+ just_now: int = int(datetime.now(tz=timezone.utc).timestamp())
211
216
  if just_now > reserved_claims.get("exp"):
212
217
  # where is the JWT service provider ?
213
218
  if control_data.get("remote-provider"):
pypomes_jwt/jwt_pomes.py CHANGED
@@ -296,14 +296,15 @@ def jwt_service(account_id: str = None,
296
296
  """
297
297
  Entry point for obtaining JWT tokens.
298
298
 
299
- In order to be serviced, the invoker must send, as parameter *service_params* or in the body of the request:
299
+ Access might be through direct invocation, or through a REST request. In either case,
300
+ the invoker must send, as parameter *service_params* or in the body of the request:
300
301
  {
301
302
  "account-id": "<string>" - required account identification
302
- "<custom-claim-key-1>": "<custom-claim-value-1>", - optional custom claims
303
+ "<custom-claim-key-1>": "<custom-claim-value-1>", - optional superceding custom claims
303
304
  ...
304
305
  "<custom-claim-key-n>": "<custom-claim-value-n>"
305
306
  }
306
- If provided, the additional custom claims will be sent to the remote provider, if applicable
307
+ If provided, the superceding custom claims will be sent to the remote provider, if applicable
307
308
  (custom claims currently registered for the account may be overridden).
308
309
 
309
310
 
@@ -323,10 +324,7 @@ def jwt_service(account_id: str = None,
323
324
  result: Response
324
325
 
325
326
  if logger:
326
- msg: str = "Service a JWT request"
327
- if request:
328
- msg += f" from '{request.base_url}'"
329
- logger.debug(msg=msg)
327
+ logger.debug(msg="Service a JWT request")
330
328
 
331
329
  # retrieve the parameters
332
330
  # noinspection PyUnusedLocal
@@ -335,22 +333,18 @@ def jwt_service(account_id: str = None,
335
333
  with contextlib.suppress(Exception):
336
334
  params = request.get_json()
337
335
  if not account_id:
338
- account_id = params.get("account-id")
336
+ account_id = params.pop("account-id", None)
339
337
 
340
338
  # has the account been identified ?
341
339
  if account_id:
342
340
  # yes, proceed
343
341
  if logger:
344
342
  logger.debug(msg=f"Account identification is '{account_id}'")
345
- item_data: dict[str, dict[str, Any]] = __jwt_data.get_access_data(account_id=account_id,
346
- logger=logger) or {}
347
- custom_claims: dict[str, Any] = item_data.get("custom-claims").copy()
348
- for key, value in params.items():
349
- custom_claims[key] = value
350
343
 
351
344
  # obtain the token data
352
345
  try:
353
346
  token_data: dict[str, Any] = __jwt_data.get_token_data(account_id=account_id,
347
+ superceding_claims=params,
354
348
  logger=logger)
355
349
  result = jsonify(token_data)
356
350
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 0.6.4
3
+ Version: 0.6.5
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
@@ -0,0 +1,7 @@
1
+ pypomes_jwt/__init__.py,sha256=m0USOMlGVUfofwukykKf6DAPq7CRn4SiY6CeNOOiqJ8,998
2
+ pypomes_jwt/jwt_data.py,sha256=skSwtbBemyanuWyngu0lq2Yw3-hONytt1AwXZpSlILg,19541
3
+ pypomes_jwt/jwt_pomes.py,sha256=pWYjCRKIcaG-yN64IgJ54L-YHw3Jhhnmsvb6xMipQsY,14515
4
+ pypomes_jwt-0.6.5.dist-info/METADATA,sha256=KZBLb8BEdIDaFQMoCxvkQ-ZBzIN97RaVXV49uAizNvo,599
5
+ pypomes_jwt-0.6.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ pypomes_jwt-0.6.5.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
7
+ pypomes_jwt-0.6.5.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- pypomes_jwt/__init__.py,sha256=m0USOMlGVUfofwukykKf6DAPq7CRn4SiY6CeNOOiqJ8,998
2
- pypomes_jwt/jwt_data.py,sha256=h_FbKrbnN9eLQYtzTQwCd1hZQYGCidHJy4rG9iBn8hs,19181
3
- pypomes_jwt/jwt_pomes.py,sha256=U8Vc0IOlW5-XmRR_Px2xLlVit5oAHVnfBcNwDzwh_8I,14786
4
- pypomes_jwt-0.6.4.dist-info/METADATA,sha256=vwG7SQieuLoTIRP2wqMCZ-DnK-XUqiajFnezKD5Bt1s,599
5
- pypomes_jwt-0.6.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
- pypomes_jwt-0.6.4.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
7
- pypomes_jwt-0.6.4.dist-info/RECORD,,