pypomes-iam 0.4.4__py3-none-any.whl → 0.4.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-iam might be problematic. Click here for more details.

pypomes_iam/iam_common.py CHANGED
@@ -28,8 +28,7 @@ class IamServer(StrEnum):
28
28
  # "pk-lifetime": <int>,
29
29
  # "pk-expiration": <int>,
30
30
  # "base-url": <str>,
31
- # "cache": <FIFOCache>,
32
- # "redirect-uri": <str> <-- transient
31
+ # "cache": <FIFOCache>
33
32
  # },
34
33
  # ...
35
34
  # }
@@ -41,8 +40,10 @@ class IamServer(StrEnum):
41
40
  # "refresh-token": <str>
42
41
  # "access-expiration": <timestamp>,
43
42
  # "refresh-expiration": <timestamp>,
44
- # "login-expiration": <timestamp>, <-- transient
45
- # "login-id": <str>, <-- transient
43
+ # # transient attributes:
44
+ # "login-expiration": <timestamp>,
45
+ # "login-id": <str>,
46
+ # "redirect-uri": <str>
46
47
  # }
47
48
  # },
48
49
  # ...
pypomes_iam/iam_pomes.py CHANGED
@@ -62,13 +62,13 @@ def user_login(iam_server: IamServer,
62
62
  user_data["login-expiration"] = int(datetime.now(tz=TZ_LOCAL).timestamp()) + timeout \
63
63
  if timeout else None
64
64
  redirect_uri: str = args.get("redirect-uri")
65
+ user_data["redirect-uri"] = redirect_uri
65
66
 
66
67
  # build the login url
67
68
  registry: dict[str, Any] = _get_iam_registry(iam_server=iam_server,
68
69
  errors=errors,
69
70
  logger=logger)
70
71
  if registry:
71
- registry["redirect-uri"] = redirect_uri
72
72
  result = (f"{registry["base-url"]}/protocol/openid-connect/auth"
73
73
  f"?response_type=code&scope=openid"
74
74
  f"&client_id={registry["client-id"]}"
@@ -203,7 +203,7 @@ def login_callback(iam_server: IamServer,
203
203
 
204
204
  The relevant expected arguments in *args* are:
205
205
  - *state*: used to enhance security during the authorization process, typically to provide *CSRF* protection
206
- - *code*: the temporary authorization code, to be exchanged for the token
206
+ - *code*: the temporary authorization code provided by *iam_server*, to be exchanged for the token
207
207
 
208
208
  :param iam_server: the reference registered *IAM* server
209
209
  :param args: the arguments passed when requesting the service
@@ -215,11 +215,10 @@ def login_callback(iam_server: IamServer,
215
215
  result: tuple[str, str] | None = None
216
216
 
217
217
  with _iam_lock:
218
- # retrieve the IAM server's registry and the data for all users therein
219
- registry: dict[str, Any] = _get_iam_registry(iam_server=iam_server,
220
- errors=errors,
221
- logger=logger)
222
- users: dict[str, dict[str, Any]] = (registry["cache"]["users"] or {}) if registry else {}
218
+ # retrieve the IAM server's data for all users
219
+ users: dict[str, dict[str, Any]] = _get_iam_users(iam_server=iam_server,
220
+ errors=errors,
221
+ logger=logger) or {}
223
222
  # retrieve the OAuth2 state
224
223
  oauth_state: str = args.get("state")
225
224
  user_data: dict[str, Any] | None = None
@@ -240,7 +239,7 @@ def login_callback(iam_server: IamServer,
240
239
  body_data: dict[str, Any] = {
241
240
  "grant_type": "authorization_code",
242
241
  "code": code,
243
- "redirect_uri": registry["redirect-uri"]
242
+ "redirect_uri": user_data.pop("redirect-uri")
244
243
  }
245
244
  now: int = int(datetime.now(tz=TZ_LOCAL).timestamp())
246
245
  token_data: dict[str, Any] = __post_for_token(iam_server=iam_server,
@@ -256,7 +255,7 @@ def login_callback(iam_server: IamServer,
256
255
  errors=errors,
257
256
  logger=logger)
258
257
  else:
259
- msg: str = "Unknown state received"
258
+ msg: str = f"State '{oauth_state}' not found in {iam_server}'s registry"
260
259
  if logger:
261
260
  logger.error(msg=msg)
262
261
  if isinstance(errors, list):
@@ -399,14 +398,16 @@ def __post_for_token(iam_server: IamServer,
399
398
  # complete the data to send in body of request
400
399
  body_data["client_id"] = registry["client-id"]
401
400
  client_secret: str = registry["client-secret"]
402
- if client_secret:
403
- body_data["client_secret"] = client_secret
404
401
 
405
402
  # obtain the token
406
403
  url: str = registry["base-url"] + "/protocol/openid-connect/token"
404
+
405
+ # log the POST ('client_secret' data must not be shown in log)
407
406
  if logger:
408
407
  logger.debug(msg=f"POST '{url}', data {json.dumps(obj=body_data,
409
408
  ensure_ascii=False)}")
409
+ if client_secret:
410
+ body_data["client_secret"] = client_secret
410
411
  try:
411
412
  # typical return on a token request:
412
413
  # {
@@ -72,7 +72,7 @@ def service_login() -> Response:
72
72
 
73
73
  # log the response
74
74
  if __IAM_LOGGER:
75
- __IAM_LOGGER.debug(msg=f"Response {result}")
75
+ __IAM_LOGGER.debug(msg=f"Response {result}, {result.get_data(as_text=True)}")
76
76
 
77
77
  return result
78
78
 
@@ -137,7 +137,7 @@ def service_callback() -> Response:
137
137
 
138
138
  The relevant expected request arguments are:
139
139
  - *state*: used to enhance security during the authorization process, typically to provide *CSRF* protection
140
- - *code*: the temporary authorization code, to be exchanged for the token
140
+ - *code*: the temporary authorization code provided by the IAM server, to be exchanged for the token
141
141
 
142
142
  On success, the returned *Response* will contain the following JSON:
143
143
  {
@@ -173,7 +173,7 @@ def service_callback() -> Response:
173
173
  "token": token_data[1]})
174
174
  # log the response
175
175
  if __IAM_LOGGER:
176
- __IAM_LOGGER.debug(msg=f"Response {result}")
176
+ __IAM_LOGGER.debug(msg=f"Response {result}, {result.get_data(as_text=True)}")
177
177
 
178
178
  return result
179
179
 
@@ -234,7 +234,7 @@ def service_token() -> Response:
234
234
  "token": token})
235
235
  # log the response
236
236
  if __IAM_LOGGER:
237
- __IAM_LOGGER.debug(msg=f"Response {result}")
237
+ __IAM_LOGGER.debug(msg=f"Response {result}, {result.get_data(as_text=True)}")
238
238
 
239
239
  return result
240
240
 
@@ -291,7 +291,7 @@ def service_exchange() -> Response:
291
291
 
292
292
  # log the response
293
293
  if __IAM_LOGGER:
294
- __IAM_LOGGER.debug(msg=f"Response {result}")
294
+ __IAM_LOGGER.debug(msg=f"Response {result}, {result.get_data(as_text=True)}")
295
295
 
296
296
  return result
297
297
 
@@ -72,8 +72,7 @@ def jusbr_setup(flask_app: Flask,
72
72
  "base-url": base_url,
73
73
  "pk-expiration": sys.maxsize,
74
74
  "pk-lifetime": public_key_lifetime,
75
- "cache": cache,
76
- "redirect-uri": None
75
+ "cache": cache
77
76
  }
78
77
 
79
78
  # establish the endpoints
@@ -81,8 +81,7 @@ def keycloak_setup(flask_app: Flask,
81
81
  "base-url": f"{base_url}/realms/{realm}",
82
82
  "pk-expiration": sys.maxsize,
83
83
  "pk-lifetime": public_key_lifetime,
84
- "cache": cache,
85
- "redirect-uri": None
84
+ "cache": cache
86
85
  }
87
86
 
88
87
  # establish the endpoints
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_iam
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: A collection of Python pomes, penyeach (IAM modules)
5
5
  Project-URL: Homepage, https://github.com/TheWiseCoder/PyPomes-IAM
6
6
  Project-URL: Bug Tracker, https://github.com/TheWiseCoder/PyPomes-IAM/issues
@@ -0,0 +1,12 @@
1
+ pypomes_iam/__init__.py,sha256=KX_QLdqAD-dNUl3G1mDeutxL9e58S9OsMoJlrgM9R28,1027
2
+ pypomes_iam/iam_common.py,sha256=duAi5kUpJZTm_66DcamdARLIIhfTvFZLuLcNd4QPel8,9323
3
+ pypomes_iam/iam_pomes.py,sha256=JkvdDZbkcg-xfwcYeUHpvVfpaLcd1pHnCfaVY2NlUyo,24240
4
+ pypomes_iam/iam_services.py,sha256=lNJUwJHGGdcTKtbSzdGH5FeD9yjvXGYjNHApuzyXgxc,11651
5
+ pypomes_iam/jusbr_pomes.py,sha256=lZ_NhHbYj17hI9o_hdxvGiKaIlxRu3y1jVypb57VX4E,5723
6
+ pypomes_iam/keycloak_pomes.py,sha256=GSqCEa82r5t0Rz9Tp5GI0eJHjfA3dqufgFZIzOO_Z2o,6740
7
+ pypomes_iam/provider_pomes.py,sha256=vfVaLGYCKSAjoB58CTw4hnUQHriMONHql_5hxjCEeHE,6358
8
+ pypomes_iam/token_pomes.py,sha256=1g6PMNNMbmdwLrsvSXvpO8-zdRhso1IFnwAyndNmV4Q,5332
9
+ pypomes_iam-0.4.6.dist-info/METADATA,sha256=wKKN0cityUzE8n6OoxFEmjcIaVaULSrgPCnF0bWeZok,694
10
+ pypomes_iam-0.4.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
+ pypomes_iam-0.4.6.dist-info/licenses/LICENSE,sha256=YvUELgV8qvXlaYsy9hXG5EW3Bmsrkw-OJmmILZnonAc,1086
12
+ pypomes_iam-0.4.6.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- pypomes_iam/__init__.py,sha256=KX_QLdqAD-dNUl3G1mDeutxL9e58S9OsMoJlrgM9R28,1027
2
- pypomes_iam/iam_common.py,sha256=RRWWhoqJZTx8sOHF-wQsu5yymMxAi5LB46Wz3kN54lQ,9348
3
- pypomes_iam/iam_pomes.py,sha256=9VXp2qq80hop7vb8echAlvpCnAE2zKilEUd7aA3Y6xA,24201
4
- pypomes_iam/iam_services.py,sha256=jZVMp37KYuV1C0YWG1yZ3vCoMmW95vkR7b4qASXhjyI,11492
5
- pypomes_iam/jusbr_pomes.py,sha256=G-COBstBeQeD7dPgvf2MI1E8r2-ACHHwzhyfsphhKgw,5758
6
- pypomes_iam/keycloak_pomes.py,sha256=JxVVFdhXJypK5x9ocn7283pB1xJbS-yPgStkSFS12HM,6775
7
- pypomes_iam/provider_pomes.py,sha256=vfVaLGYCKSAjoB58CTw4hnUQHriMONHql_5hxjCEeHE,6358
8
- pypomes_iam/token_pomes.py,sha256=1g6PMNNMbmdwLrsvSXvpO8-zdRhso1IFnwAyndNmV4Q,5332
9
- pypomes_iam-0.4.4.dist-info/METADATA,sha256=FiPANYywqOSOlBTww7wW2AICPia3ULbplX4WCzDdgcs,694
10
- pypomes_iam-0.4.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- pypomes_iam-0.4.4.dist-info/licenses/LICENSE,sha256=YvUELgV8qvXlaYsy9hXG5EW3Bmsrkw-OJmmILZnonAc,1086
12
- pypomes_iam-0.4.4.dist-info/RECORD,,