pypomes-iam 0.0.8__tar.gz → 0.1.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-iam might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_iam
3
- Version: 0.0.8
3
+ Version: 0.1.0
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
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "pypomes_iam"
9
- version = "0.0.8"
9
+ version = "0.1.0"
10
10
  authors = [
11
11
  { name="GT Nunes", email="wisecoder01@gmail.com" }
12
12
  ]
@@ -13,26 +13,20 @@ from typing import Any, Final
13
13
 
14
14
  JUSBR_CLIENT_ID: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CLIENT_ID")
15
15
  JUSBR_CLIENT_SECRET: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CLIENT_SECRET")
16
- JUSBR_LOGIN_TIMEOUT: Final[int] = env_get_int(key=f"{APP_PREFIX}_JUSBR_LOGIN_TIMEOUT")
16
+ JUSBR_CLIENT_TIMEOUT: Final[int] = env_get_int(key=f"{APP_PREFIX}_JUSBR_CLIENT_TIMEOUT")
17
17
 
18
- JUSBR_CALLBACK_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CALLBACK_ENDPOINT",
18
+ JUSBR_ENDPOINT_CALLBACK: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_CALLBACK",
19
19
  def_value="/iam/jusbr:callback")
20
- JUSBR_TOKEN_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_TOKEN_ENDPOINT",
21
- def_value="/iam/jusbr:get-token")
22
- JUSBR_LOGIN_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_LOGIN_ENDPOINT",
20
+ JUSBR_ENDPOINT_LOGIN: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_LOGIN",
23
21
  def_value="/iam/jusbr:login")
24
- JUSBR_LOGOUT_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_LOGOUT_ENDPOINT",
22
+ JUSBR_ENDPOINT_LOGOUT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_LOGOUT",
25
23
  def_value="/iam/jusbr:logout")
24
+ JUSBR_ENDPOINT_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_TOKEN",
25
+ def_value="/iam/jusbr:get-token")
26
26
 
27
- JUSBR_CALLBACK_URL: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CALLBACK_URL")
28
- JUSBR_AUTH_URL: Final[str] = env_get_str(
29
- key=f"{APP_PREFIX}JUSBR_AUTH_URL",
30
- def_value="https://sso.stg.cloud.pje.jus.br/auth/realms/pje/protocol/openid-connect/auth"
31
- )
32
- JUSBR_TOKEN_URL: Final[str] = env_get_str(
33
- key=f"{APP_PREFIX}JUSBR_TOKEN_URL",
34
- def_value="https://sso.stg.cloud.pje.jus.br/auth/realms/pje/protocol/openid-connect/token"
35
- )
27
+ JUSBR_URL_AUTH_CALLBACK: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_URL_AUTH_CALLBACK")
28
+ JUSBR_URL_AUTH_LOGIN: Final[str] = env_get_str(key=f"{APP_PREFIX}JUSBR_URL_AUTH_LOGIN")
29
+ JUSBR_URL_AUTH_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}JUSBR_URL_AUTH_TOKEN")
36
30
 
37
31
  # safe memory cache - structure:
38
32
  # {
@@ -40,8 +34,8 @@ JUSBR_TOKEN_URL: Final[str] = env_get_str(
40
34
  # "client-secret": <str>,
41
35
  # "auth-url": <str>,
42
36
  # "token-url": <str>,
43
- # "login-timeout": <int>,
44
- # "users": [
37
+ # "client-timeout": <int>,
38
+ # "users": {
45
39
  # "<user-id>": {
46
40
  # "cache-obj": <Cache>,
47
41
  # "oauth-scope": <str>,
@@ -51,16 +45,16 @@ JUSBR_TOKEN_URL: Final[str] = env_get_str(
51
45
  # "access-token": <str>
52
46
  # "refresh-token": <str>
53
47
  # }
54
- # ]
48
+ # }
55
49
  # }
56
50
  _jusbr_registry: dict[str, Any] = {
57
51
  "client-id": None,
58
52
  "client-secret": None,
59
- "login-timeout": None,
53
+ "client-timeout": None,
60
54
  "auth-url": None,
61
55
  "callback-url": None,
62
56
  "token-url": None,
63
- "users": []
57
+ "users": {}
64
58
  }
65
59
 
66
60
  # dafault logger
@@ -70,14 +64,14 @@ _logger: Logger | None = None
70
64
  def jusbr_setup(flask_app: Flask,
71
65
  client_id: str = JUSBR_CLIENT_ID,
72
66
  client_secret: str = JUSBR_CLIENT_SECRET,
73
- login_timeout: int = JUSBR_LOGIN_TIMEOUT,
74
- callback_endpoint: str = JUSBR_CALLBACK_ENDPOINT,
75
- token_endpoint: str = JUSBR_TOKEN_ENDPOINT,
76
- login_endpoint: str = JUSBR_LOGIN_ENDPOINT,
77
- logout_endpoint: str = JUSBR_LOGOUT_ENDPOINT,
78
- auth_url: str = JUSBR_AUTH_URL,
79
- callback_url: str = JUSBR_CALLBACK_URL,
80
- token_url: str = JUSBR_TOKEN_URL,
67
+ client_timeout: int = JUSBR_CLIENT_TIMEOUT,
68
+ callback_endpoint: str = JUSBR_ENDPOINT_CALLBACK,
69
+ token_endpoint: str = JUSBR_ENDPOINT_TOKEN,
70
+ login_endpoint: str = JUSBR_ENDPOINT_LOGIN,
71
+ logout_endpoint: str = JUSBR_ENDPOINT_LOGOUT,
72
+ auth_url: str = JUSBR_URL_AUTH_LOGIN,
73
+ callback_url: str = JUSBR_URL_AUTH_CALLBACK,
74
+ token_url: str = JUSBR_URL_AUTH_TOKEN,
81
75
  logger: Logger = None) -> None:
82
76
  """
83
77
  Configure the JusBR IAM.
@@ -87,7 +81,7 @@ def jusbr_setup(flask_app: Flask,
87
81
  :param flask_app: the Flask application
88
82
  :param client_id: the client's identification with JusBR
89
83
  :param client_secret: the client's password with JusBR
90
- :param login_timeout: timeout for login authentication (in seconds,defaults to no timeout)
84
+ :param client_timeout: timeout for login authentication (in seconds,defaults to no timeout)
91
85
  :param callback_endpoint: endpoint for the callback from JusBR
92
86
  :param token_endpoint: endpoint for retrieving the JusBR authentication token
93
87
  :param login_endpoint: endpoint for redirecting user to JusBR login page
@@ -106,7 +100,7 @@ def jusbr_setup(flask_app: Flask,
106
100
  _jusbr_registry.update({
107
101
  "client-id": client_id,
108
102
  "client-secret": client_secret,
109
- "login-timeout": login_timeout,
103
+ "client-timeout": client_timeout,
110
104
  "auth-url": auth_url,
111
105
  "callback-url": callback_url,
112
106
  "token-url": token_url
@@ -189,12 +183,12 @@ def service_logout() -> Response:
189
183
  global _jusbr_registry
190
184
 
191
185
  # retrieve user id
192
- input_params: dict[str, Any] = request.values
186
+ input_params: dict[str, Any] = request.args
193
187
  user_id: str = input_params.get("user-id") or input_params.get("login")
194
188
 
195
189
  # remove user data
196
190
  if user_id in _jusbr_registry.get("users"):
197
- _jusbr_registry.pop(user_id)
191
+ _jusbr_registry["users"].pop(user_id)
198
192
  if _logger:
199
193
  _logger.debug(f"User '{user_id}' removed from the registry")
200
194
 
@@ -262,7 +256,7 @@ def service_token() -> Response:
262
256
  :return: the response containing the token, or *NOT AUTHORIZED*
263
257
  """
264
258
  # retrieve user id
265
- input_params: dict[str, Any] = request.values
259
+ input_params: dict[str, Any] = request.args
266
260
  user_id: str = input_params.get("user-id") or input_params.get("login")
267
261
 
268
262
  # retrieve the token
@@ -293,9 +287,10 @@ def jusbr_get_token(user_id: str,
293
287
  # initialize the return variable
294
288
  result: str | None = None
295
289
 
296
- user_data: dict[str, Any] = _jusbr_registry["users"].get(user_id)
297
- safe_cache: Cache = user_data["cache-obj"] if user_data else None
298
- if user_data and safe_cache:
290
+ user_data: dict[str, Any] = __get_user_data(user_id=user_id,
291
+ logger=logger)
292
+ safe_cache: Cache = user_data.get("cache-obj")
293
+ if safe_cache:
299
294
  access_expiration: int = user_data.get("access-expiration")
300
295
  now: int = int(datetime.now(tz=TZ_LOCAL).timestamp())
301
296
  if now < access_expiration:
@@ -353,7 +348,7 @@ def __get_login_timeout() -> int | None:
353
348
  """
354
349
  global _jusbr_registry
355
350
 
356
- timeout: int = _jusbr_registry.get("login-timeout")
351
+ timeout: int = _jusbr_registry.get("client-timeout")
357
352
  return timeout if isinstance(timeout, int) and timeout > 0 else None
358
353
 
359
354
 
File without changes
File without changes
File without changes