pypomes-iam 0.0.9__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.
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/PKG-INFO +1 -1
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/pyproject.toml +1 -1
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/src/pypomes_iam/jusbr_pomes.py +48 -36
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/.gitignore +0 -0
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/LICENSE +0 -0
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/README.md +0 -0
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/src/pypomes_iam/__init__.py +0 -0
- {pypomes_iam-0.0.9 → pypomes_iam-0.1.1}/src/pypomes_iam/provider_pomes.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_iam
|
|
3
|
-
Version: 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
|
|
@@ -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}
|
|
29
|
-
JUSBR_URL_AUTH_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}
|
|
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
|
# {
|
|
@@ -35,7 +35,7 @@ JUSBR_URL_AUTH_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}JUSBR_URL_AUTH_
|
|
|
35
35
|
# "auth-url": <str>,
|
|
36
36
|
# "token-url": <str>,
|
|
37
37
|
# "client-timeout": <int>,
|
|
38
|
-
# "users":
|
|
38
|
+
# "users": {
|
|
39
39
|
# "<user-id>": {
|
|
40
40
|
# "cache-obj": <Cache>,
|
|
41
41
|
# "oauth-scope": <str>,
|
|
@@ -45,7 +45,7 @@ JUSBR_URL_AUTH_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}JUSBR_URL_AUTH_
|
|
|
45
45
|
# "access-token": <str>
|
|
46
46
|
# "refresh-token": <str>
|
|
47
47
|
# }
|
|
48
|
-
#
|
|
48
|
+
# }
|
|
49
49
|
# }
|
|
50
50
|
_jusbr_registry: dict[str, Any] = {
|
|
51
51
|
"client-id": None,
|
|
@@ -54,7 +54,7 @@ _jusbr_registry: dict[str, Any] = {
|
|
|
54
54
|
"auth-url": None,
|
|
55
55
|
"callback-url": None,
|
|
56
56
|
"token-url": None,
|
|
57
|
-
"users":
|
|
57
|
+
"users": {}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
# dafault logger
|
|
@@ -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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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
|
-
|
|
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,17 +187,17 @@ def service_logout() -> Response:
|
|
|
178
187
|
|
|
179
188
|
Remove all data associating the user with JusBR from the registry.
|
|
180
189
|
|
|
181
|
-
:return:
|
|
190
|
+
:return: response *OK*
|
|
182
191
|
"""
|
|
183
192
|
global _jusbr_registry
|
|
184
193
|
|
|
185
194
|
# retrieve user id
|
|
186
|
-
input_params: dict[str, Any] = request.
|
|
195
|
+
input_params: dict[str, Any] = request.args
|
|
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"):
|
|
191
|
-
_jusbr_registry.pop(user_id)
|
|
199
|
+
if user_id and user_id in _jusbr_registry.get("users"):
|
|
200
|
+
_jusbr_registry["users"].pop(user_id)
|
|
192
201
|
if _logger:
|
|
193
202
|
_logger.debug(f"User '{user_id}' removed from the registry")
|
|
194
203
|
|
|
@@ -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 *
|
|
265
|
+
:return: the response containing the token, or *UNAUTHORIZED*
|
|
257
266
|
"""
|
|
258
267
|
# retrieve user id
|
|
259
|
-
input_params: dict[str, Any] = request.
|
|
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(
|
|
279
|
+
result = Response("; ".join(errors))
|
|
280
|
+
result.status_code = 401
|
|
270
281
|
|
|
271
282
|
return result
|
|
272
283
|
|
|
@@ -287,9 +298,10 @@ def jusbr_get_token(user_id: str,
|
|
|
287
298
|
# initialize the return variable
|
|
288
299
|
result: str | None = None
|
|
289
300
|
|
|
290
|
-
user_data: dict[str, Any] =
|
|
291
|
-
|
|
292
|
-
|
|
301
|
+
user_data: dict[str, Any] = __get_user_data(user_id=user_id,
|
|
302
|
+
logger=logger)
|
|
303
|
+
safe_cache: Cache = user_data.get("cache-obj")
|
|
304
|
+
if safe_cache:
|
|
293
305
|
access_expiration: int = user_data.get("access-expiration")
|
|
294
306
|
now: int = int(datetime.now(tz=TZ_LOCAL).timestamp())
|
|
295
307
|
if now < access_expiration:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|