pypomes-iam 0.1.0__tar.gz → 0.1.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypomes_iam
3
- Version: 0.1.0
3
+ Version: 0.1.1
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.1.0"
9
+ version = "0.1.1"
10
10
  authors = [
11
11
  { name="GT Nunes", email="wisecoder01@gmail.com" }
12
12
  ]
@@ -25,8 +25,8 @@ JUSBR_ENDPOINT_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT
25
25
  def_value="/iam/jusbr:get-token")
26
26
 
27
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")
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")
30
30
 
31
31
  # safe memory cache - structure:
32
32
  # {
@@ -141,33 +141,42 @@ def service_login() -> Response:
141
141
  """
142
142
  global _jusbr_registry
143
143
 
144
+ # declare the return variable
145
+ result: Response
146
+
144
147
  # retrieve user id
145
148
  input_params: dict[str, Any] = request.values
146
149
  user_id: str = input_params.get("user-id") or input_params.get("login")
147
150
 
148
- # retrieve user data
149
- user_data: dict[str, Any] = __get_user_data(user_id=user_id,
150
- logger=_logger)
151
- # build redirect url
152
- oauth_state: str = "".join(secrets.choice(string.ascii_letters + string.digits) for _ in range(16))
153
- timeout: int = __get_login_timeout()
154
- safe_cache: Cache
155
- if timeout:
156
- safe_cache = TTLCache(maxsize=16,
157
- ttl=600)
151
+ if user_id:
152
+ # retrieve user data
153
+ user_data: dict[str, Any] = __get_user_data(user_id=user_id,
154
+ logger=_logger)
155
+ # build redirect url
156
+ oauth_state: str = "".join(secrets.choice(string.ascii_letters + string.digits) for _ in range(16))
157
+ timeout: int = __get_login_timeout()
158
+ safe_cache: Cache
159
+ if timeout:
160
+ safe_cache = TTLCache(maxsize=16,
161
+ ttl=600)
162
+ else:
163
+ safe_cache = FIFOCache(maxsize=16)
164
+ safe_cache["oauth-state"] = oauth_state
165
+ user_data["cache-obj"] = safe_cache
166
+ auth_url: str = (f"{_jusbr_registry["auth-url"]}?response_type=code"
167
+ f"&client_id={_jusbr_registry["client-id"]}"
168
+ f"&redirect_url={_jusbr_registry["callback-url"]}"
169
+ f"&state={oauth_state}")
170
+ if user_data.get("oauth-scope"):
171
+ auth_url += f"&scope={user_data.get("oauth-scope")}"
172
+
173
+ # redirect request
174
+ result = redirect(location=auth_url)
158
175
  else:
159
- safe_cache = FIFOCache(maxsize=16)
160
- safe_cache["oauth-state"] = oauth_state
161
- user_data["cache-obj"] = safe_cache
162
- auth_url: str = (f"{_jusbr_registry["auth-url"]}?response_type=code"
163
- f"&client_id={_jusbr_registry["client-id"]}"
164
- f"&redirect_url={_jusbr_registry["callback-url"]}"
165
- f"&state={oauth_state}")
166
- if user_data.get("oauth-scope"):
167
- auth_url += f"&scope={user_data.get("oauth-scope")}"
176
+ result = jsonify({"errors": "User id must be provided"})
177
+ result.status_code = 401
168
178
 
169
- # redirect request
170
- return redirect(location=auth_url)
179
+ return result
171
180
 
172
181
 
173
182
  # @flask_app.route(rule=<login_endpoint>, # JUSBR_LOGIN_ENDPOINT: /iam/jusbr:logout
@@ -178,7 +187,7 @@ def service_logout() -> Response:
178
187
 
179
188
  Remove all data associating the user with JusBR from the registry.
180
189
 
181
- :return: the response from the redirect operation
190
+ :return: response *OK*
182
191
  """
183
192
  global _jusbr_registry
184
193
 
@@ -187,7 +196,7 @@ def service_logout() -> Response:
187
196
  user_id: str = input_params.get("user-id") or input_params.get("login")
188
197
 
189
198
  # remove user data
190
- if user_id in _jusbr_registry.get("users"):
199
+ if user_id and user_id in _jusbr_registry.get("users"):
191
200
  _jusbr_registry["users"].pop(user_id)
192
201
  if _logger:
193
202
  _logger.debug(f"User '{user_id}' removed from the registry")
@@ -253,20 +262,22 @@ def service_token() -> Response:
253
262
  """
254
263
  Entry point for retrieving the JusBR token.
255
264
 
256
- :return: the response containing the token, or *NOT AUTHORIZED*
265
+ :return: the response containing the token, or *UNAUTHORIZED*
257
266
  """
258
267
  # retrieve user id
259
268
  input_params: dict[str, Any] = request.args
260
269
  user_id: str = input_params.get("user-id") or input_params.get("login")
261
270
 
262
271
  # retrieve the token
272
+ errors: list[str] = []
263
273
  token: str = jusbr_get_token(user_id=user_id,
264
274
  logger=_logger)
265
275
  result: Response
266
276
  if token:
267
277
  result = jsonify({"token": token})
268
278
  else:
269
- result = Response(status=401)
279
+ result = Response("; ".join(errors))
280
+ result.status_code = 401
270
281
 
271
282
  return result
272
283
 
File without changes
File without changes
File without changes