pypomes-jwt 0.6.3__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 +11 -6
- pypomes_jwt/jwt_pomes.py +7 -13
- {pypomes_jwt-0.6.3.dist-info → pypomes_jwt-0.6.5.dist-info}/METADATA +2 -2
- pypomes_jwt-0.6.5.dist-info/RECORD +7 -0
- pypomes_jwt-0.6.3.dist-info/RECORD +0 -7
- {pypomes_jwt-0.6.3.dist-info → pypomes_jwt-0.6.5.dist-info}/WHEEL +0 -0
- {pypomes_jwt-0.6.3.dist-info → pypomes_jwt-0.6.5.dist-info}/licenses/LICENSE +0 -0
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>"
|
|
@@ -107,7 +107,7 @@ class JwtData:
|
|
|
107
107
|
"access-max-age": access_max_age,
|
|
108
108
|
"request-timeout": request_timeout,
|
|
109
109
|
"remote-provider": remote_provider,
|
|
110
|
-
"refresh-exp": datetime.now(tz=timezone.utc).timestamp() + refresh_max_age
|
|
110
|
+
"refresh-exp": int(datetime.now(tz=timezone.utc).timestamp()) + refresh_max_age
|
|
111
111
|
}
|
|
112
112
|
if algorithm in ["HS256", "HS512"]:
|
|
113
113
|
control_data["hs-secret-key"] = hs_secret_key
|
|
@@ -119,8 +119,8 @@ class JwtData:
|
|
|
119
119
|
reserved_claims: dict[str, Any] = {
|
|
120
120
|
"sub": account_id,
|
|
121
121
|
"iss": reference_url,
|
|
122
|
-
"exp":
|
|
123
|
-
"iat":
|
|
122
|
+
"exp": 0,
|
|
123
|
+
"iat": 0,
|
|
124
124
|
"jti": "<jwt-id>",
|
|
125
125
|
}
|
|
126
126
|
custom_claims: dict[str, Any] = {}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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
|
|
@@ -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.
|
|
15
|
+
Requires-Dist: pypomes-core>=1.7.9
|
|
@@ -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=5GB5NgmVeTJinlfIAO7BaWO0aPCETqG3dxm-aP99pCk,19222
|
|
3
|
-
pypomes_jwt/jwt_pomes.py,sha256=U8Vc0IOlW5-XmRR_Px2xLlVit5oAHVnfBcNwDzwh_8I,14786
|
|
4
|
-
pypomes_jwt-0.6.3.dist-info/METADATA,sha256=WaVMfTzEO-cnKmP7XDm-p8owJxmIhzua6yk61s0l86E,599
|
|
5
|
-
pypomes_jwt-0.6.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
-
pypomes_jwt-0.6.3.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
|
|
7
|
-
pypomes_jwt-0.6.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|