pypomes-jwt 0.6.5__py3-none-any.whl → 0.6.6__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_needed, jwt_verify_request, jwt_service,
9
- jwt_get_token_claims, jwt_get_token, jwt_get_token_data,
8
+ jwt_needed, jwt_verify_request, jwt_claims, jwt_token,
9
+ jwt_get_token_data, jwt_get_token_claims,
10
10
  jwt_assert_access, jwt_set_access, jwt_remove_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_needed", "jwt_verify_request", "jwt_service",
21
- "jwt_get_token_claims", "jwt_get_token", "jwt_get_token_data",
20
+ "jwt_needed", "jwt_verify_request", "jwt_claims", "jwt_token",
21
+ "jwt_get_token_data", "jwt_get_token_claims",
22
22
  "jwt_assert_access", "jwt_set_access", "jwt_remove_access"
23
23
  ]
24
24
 
pypomes_jwt/jwt_pomes.py CHANGED
@@ -137,42 +137,12 @@ def jwt_remove_access(account_id: str,
137
137
  logger=logger)
138
138
 
139
139
 
140
- def jwt_get_token(errors: list[str],
141
- account_id: str,
142
- logger: Logger = None) -> str:
143
- """
144
- Obtain and return a JWT token for *account_id*.
145
-
146
- :param errors: incidental error messages
147
- :param account_id: the account identification
148
- :param logger: optional logger
149
- :return: the JWT token, or *None* if an error ocurred
150
- """
151
- # inicialize the return variable
152
- result: str | None = None
153
-
154
- if logger:
155
- logger.debug(msg=f"Obtain a JWT token for '{account_id}'")
156
-
157
- try:
158
- token_data: dict[str, Any] = __jwt_data.get_token_data(account_id=account_id,
159
- logger=logger)
160
- result = token_data.get("access_token")
161
- if logger:
162
- logger.debug(f"Token is '{result}'")
163
- except Exception as e:
164
- if logger:
165
- logger.error(msg=str(e))
166
- errors.append(str(e))
167
-
168
- return result
169
-
170
-
171
140
  def jwt_get_token_data(errors: list[str],
172
141
  account_id: str,
142
+ superceding_claims: dict[str, Any] = None,
173
143
  logger: Logger = None) -> dict[str, Any]:
174
144
  """
175
- Obtain and return the JWT token associated with *account_id*, along with its duration.
145
+ Obtain and return the JWT token data associated with *account_id*.
176
146
 
177
147
  Structure of the return data:
178
148
  {
@@ -183,6 +153,7 @@ def jwt_get_token_data(errors: list[str],
183
153
 
184
154
  :param errors: incidental error messages
185
155
  :param account_id: the account identification
156
+ :param superceding_claims: if provided, may supercede registered custom claims
186
157
  :param logger: optional logger
187
158
  :return: the JWT token data, or *None* if error
188
159
  """
@@ -193,6 +164,7 @@ def jwt_get_token_data(errors: list[str],
193
164
  logger.debug(msg=f"Retrieve JWT token data for '{account_id}'")
194
165
  try:
195
166
  result = __jwt_data.get_token_data(account_id=account_id,
167
+ superceding_claims=superceding_claims,
196
168
  logger=logger)
197
169
  if logger:
198
170
  logger.debug(msg=f"Data is '{result}'")
@@ -290,14 +262,54 @@ def jwt_verify_request(request: Request,
290
262
  return result
291
263
 
292
264
 
293
- def jwt_service(account_id: str = None,
294
- service_params: dict[str, Any] = None,
295
- logger: Logger = None) -> Response:
265
+ def jwt_claims(token: str = None) -> Response:
266
+ """
267
+ REST service entry point for retrieving the claims of a JWT token.
268
+
269
+ Structure of the return data:
270
+ {
271
+ "<claim-1>": <value-of-claim-1>,
272
+ ...
273
+ "<claim-n>": <value-of-claim-n>
274
+ }
275
+
276
+ :param token: the JWT token
277
+ :return: a *Response* containing the requested JWT token claims, or reporting an error
278
+ """
279
+ # declare the return variable
280
+ result: Response
281
+
282
+ # retrieve the token
283
+ # noinspection PyUnusedLocal
284
+ if not token:
285
+ token = request.values.get("token")
286
+ if not token:
287
+ with contextlib.suppress(Exception):
288
+ token = request.get_json().get("token")
289
+
290
+ # has the token been obtained ?
291
+ if token:
292
+ # yes, obtain the token data
293
+ try:
294
+ token_claims: dict[str, Any] = __jwt_data.get_token_claims(token=token)
295
+ result = jsonify(token_claims)
296
+ except Exception as e:
297
+ # claims extraction failed
298
+ result = Response(response=str(e),
299
+ status=400)
300
+ else:
301
+ # no, report the problem
302
+ result = Response(response="Invalid parameters",
303
+ status=400)
304
+
305
+ return result
306
+
307
+
308
+ def jwt_token(service_params: dict[str, Any] = None) -> Response:
296
309
  """
297
- Entry point for obtaining JWT tokens.
310
+ REST service entry point for obtaining JWT tokens.
298
311
 
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:
312
+ The requester must send, as parameter *service_params* or in the body of the request:
301
313
  {
302
314
  "account-id": "<string>" - required account identification
303
315
  "<custom-claim-key-1>": "<custom-claim-value-1>", - optional superceding custom claims
@@ -315,48 +327,33 @@ def jwt_service(account_id: str = None,
315
327
  "expires_in": <seconds-to-expiration>
316
328
  }
317
329
 
318
- :param account_id: the account identification, alternatively passed in JSON
319
330
  :param service_params: the optional JSON containing the request parameters (defaults to JSON in body)
320
- :param logger: optional logger
321
- :return: a *Response* containing the requested JWT token and its duration, or reporting an error
331
+ :return: a *Response* containing the requested JWT token data, or reporting an error
322
332
  """
323
333
  # declare the return variable
324
334
  result: Response
325
335
 
326
- if logger:
327
- logger.debug(msg="Service a JWT request")
328
-
329
336
  # retrieve the parameters
330
337
  # noinspection PyUnusedLocal
331
338
  params: dict[str, Any] = service_params or {}
332
339
  if not params:
333
340
  with contextlib.suppress(Exception):
334
341
  params = request.get_json()
335
- if not account_id:
336
- account_id = params.pop("account-id", None)
342
+ account_id: str | None = params.pop("account-id", None)
337
343
 
338
344
  # has the account been identified ?
339
345
  if account_id:
340
- # yes, proceed
341
- if logger:
342
- logger.debug(msg=f"Account identification is '{account_id}'")
343
-
344
- # obtain the token data
346
+ # yes, obtain the token data
345
347
  try:
346
348
  token_data: dict[str, Any] = __jwt_data.get_token_data(account_id=account_id,
347
- superceding_claims=params,
348
- logger=logger)
349
+ superceding_claims=params)
349
350
  result = jsonify(token_data)
350
351
  except Exception as e:
351
352
  # token validation failed
352
- if logger:
353
- logger.error(msg=str(e))
354
353
  result = Response(response=str(e),
355
354
  status=401)
356
355
  else:
357
356
  # no, report the problem
358
- if logger:
359
- logger.debug(msg=f"Invalid parameters {service_params}")
360
357
  result = Response(response="Invalid parameters",
361
358
  status=401)
362
359
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_jwt
3
- Version: 0.6.5
3
+ Version: 0.6.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
@@ -0,0 +1,7 @@
1
+ pypomes_jwt/__init__.py,sha256=CwpFtZEi1Yo1i4ulyR65yvo_fJpSRMJsXwzV75E3K0A,988
2
+ pypomes_jwt/jwt_data.py,sha256=skSwtbBemyanuWyngu0lq2Yw3-hONytt1AwXZpSlILg,19541
3
+ pypomes_jwt/jwt_pomes.py,sha256=mC7yc4DheSlkW--WYtrPPYbsg7I-vHtV37fSypc1rL8,14302
4
+ pypomes_jwt-0.6.6.dist-info/METADATA,sha256=lgYBkO8-t-uCCd9TN8E3wmINqLqU7bbqgy6bxMiRDjI,599
5
+ pypomes_jwt-0.6.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ pypomes_jwt-0.6.6.dist-info/licenses/LICENSE,sha256=NdakochSXm_H_-DSL_x2JlRCkYikj3snYYvTwgR5d_c,1086
7
+ pypomes_jwt-0.6.6.dist-info/RECORD,,
@@ -1,7 +0,0 @@
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,,