pypomes-iam 0.0.5__tar.gz → 0.0.7__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.
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/PKG-INFO +1 -1
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/pyproject.toml +1 -1
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/src/pypomes_iam/iam_jusbr.py +28 -16
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/.gitignore +0 -0
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/LICENSE +0 -0
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/README.md +0 -0
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/src/pypomes_iam/__init__.py +0 -0
- {pypomes_iam-0.0.5 → pypomes_iam-0.0.7}/src/pypomes_iam/iam_provider.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_iam
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
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
|
|
@@ -14,6 +14,7 @@ from typing import Any, Final
|
|
|
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
16
|
JUSBR_LOGIN_TIMEOUT: Final[int] = env_get_int(key=f"{APP_PREFIX}_JUSBR_LOGIN_TIMEOUT")
|
|
17
|
+
|
|
17
18
|
JUSBR_CALLBACK_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CALLBACK_ENDPOINT",
|
|
18
19
|
def_value="/iam/jusbr:callback")
|
|
19
20
|
JUSBR_TOKEN_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_TOKEN_ENDPOINT",
|
|
@@ -22,6 +23,8 @@ JUSBR_LOGIN_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_LOGIN_EN
|
|
|
22
23
|
def_value="/iam/jusbr:login")
|
|
23
24
|
JUSBR_LOGOUT_ENDPOINT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_LOGOUT_ENDPOINT",
|
|
24
25
|
def_value="/iam/jusbr:logout")
|
|
26
|
+
|
|
27
|
+
JUSBR_CALLBACK_URL: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CALLBACK_URL")
|
|
25
28
|
JUSBR_AUTH_URL: Final[str] = env_get_str(
|
|
26
29
|
key=f"{APP_PREFIX}JUSBR_AUTH_URL",
|
|
27
30
|
def_value="https://sso.stg.cloud.pje.jus.br/auth/realms/pje/protocol/openid-connect/auth"
|
|
@@ -30,7 +33,6 @@ JUSBR_TOKEN_URL: Final[str] = env_get_str(
|
|
|
30
33
|
key=f"{APP_PREFIX}JUSBR_TOKEN_URL",
|
|
31
34
|
def_value="https://sso.stg.cloud.pje.jus.br/auth/realms/pje/protocol/openid-connect/token"
|
|
32
35
|
)
|
|
33
|
-
JUSBR_CALLBACK_URL: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CALLBACK_URL")
|
|
34
36
|
|
|
35
37
|
# safe memory cache - structure:
|
|
36
38
|
# {
|
|
@@ -56,6 +58,7 @@ _jusbr_registry: dict[str, Any] = {
|
|
|
56
58
|
"client-secret": None,
|
|
57
59
|
"login-timeout": None,
|
|
58
60
|
"auth-url": None,
|
|
61
|
+
"callback-url": None,
|
|
59
62
|
"token-url": None,
|
|
60
63
|
"users": []
|
|
61
64
|
}
|
|
@@ -73,6 +76,7 @@ def jusbr_setup(flask_app: Flask,
|
|
|
73
76
|
login_endpoint: str = JUSBR_LOGIN_ENDPOINT,
|
|
74
77
|
logout_endpoint: str = JUSBR_LOGOUT_ENDPOINT,
|
|
75
78
|
auth_url: str = JUSBR_AUTH_URL,
|
|
79
|
+
callback_url: str = JUSBR_CALLBACK_URL,
|
|
76
80
|
token_url: str = JUSBR_TOKEN_URL,
|
|
77
81
|
logger: Logger = None) -> None:
|
|
78
82
|
"""
|
|
@@ -89,6 +93,7 @@ def jusbr_setup(flask_app: Flask,
|
|
|
89
93
|
:param login_endpoint: endpoint for redirecting user to JusBR login page
|
|
90
94
|
:param logout_endpoint: endpoint for terminating user access to JusBR
|
|
91
95
|
:param auth_url: URL to access the JusBR login page
|
|
96
|
+
:param callback_url: URL for JusBR to callback on login
|
|
92
97
|
:param token_url: URL for obtaing or refreshing the token
|
|
93
98
|
:param logger: optional logger
|
|
94
99
|
"""
|
|
@@ -103,6 +108,7 @@ def jusbr_setup(flask_app: Flask,
|
|
|
103
108
|
"client-secret": client_secret,
|
|
104
109
|
"login-timeout": login_timeout,
|
|
105
110
|
"auth-url": auth_url,
|
|
111
|
+
"callback-url": callback_url,
|
|
106
112
|
"token-url": token_url
|
|
107
113
|
})
|
|
108
114
|
|
|
@@ -161,7 +167,7 @@ def service_login() -> Response:
|
|
|
161
167
|
user_data["cache-obj"] = safe_cache
|
|
162
168
|
auth_url: str = (f"{_jusbr_registry["auth-url"]}?response_type=code"
|
|
163
169
|
f"&client_id={_jusbr_registry["client-id"]}"
|
|
164
|
-
f"&redirect_url={_jusbr_registry["
|
|
170
|
+
f"&redirect_url={_jusbr_registry["callback-url"]}"
|
|
165
171
|
f"&state={oauth_state}")
|
|
166
172
|
if user_data.get("oauth-scope"):
|
|
167
173
|
auth_url += f"&scope={user_data.get("oauth-scope")}"
|
|
@@ -218,18 +224,19 @@ def service_callback() -> Response:
|
|
|
218
224
|
break
|
|
219
225
|
|
|
220
226
|
# exchange 'code' for the token
|
|
227
|
+
token: str | None = None
|
|
221
228
|
errors: list[str] = []
|
|
222
229
|
if user_data:
|
|
223
230
|
code: str = request.args.get("code")
|
|
224
231
|
body_data: dict[str, Any] = {
|
|
225
232
|
"grant_type": "authorization_code",
|
|
226
233
|
"code": code,
|
|
227
|
-
"redirec_url": _jusbr_registry.get("
|
|
234
|
+
"redirec_url": _jusbr_registry.get("callback-url"),
|
|
228
235
|
}
|
|
229
|
-
__post_jusbr(user_data=user_data,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
token = __post_jusbr(user_data=user_data,
|
|
237
|
+
body_data=body_data,
|
|
238
|
+
errors=errors,
|
|
239
|
+
logger=_logger)
|
|
233
240
|
else:
|
|
234
241
|
msg: str = "Unknown OAuth2 code received"
|
|
235
242
|
if __get_login_timeout():
|
|
@@ -241,7 +248,7 @@ def service_callback() -> Response:
|
|
|
241
248
|
result = jsonify({"errors": "; ".join(errors)})
|
|
242
249
|
result.status_code = 400
|
|
243
250
|
else:
|
|
244
|
-
result =
|
|
251
|
+
result = jsonify({"access_token": token})
|
|
245
252
|
|
|
246
253
|
return result
|
|
247
254
|
|
|
@@ -279,6 +286,7 @@ def jusbr_get_token(user_id: str,
|
|
|
279
286
|
:param user_id: the user's identification
|
|
280
287
|
:param errors: incidental error messages
|
|
281
288
|
:param logger: optional logger
|
|
289
|
+
:return: the token for *user_id*, or *None* if error
|
|
282
290
|
"""
|
|
283
291
|
global _jusbr_registry
|
|
284
292
|
|
|
@@ -301,12 +309,10 @@ def jusbr_get_token(user_id: str,
|
|
|
301
309
|
"grant_type": "refresh_token",
|
|
302
310
|
"refresh_token": refresh_token
|
|
303
311
|
}
|
|
304
|
-
__post_jusbr(user_data=user_data,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if not errors:
|
|
309
|
-
result = safe_cache.get("access_token")
|
|
312
|
+
result = __post_jusbr(user_data=user_data,
|
|
313
|
+
body_data=body_data,
|
|
314
|
+
errors=errors,
|
|
315
|
+
logger=logger)
|
|
310
316
|
|
|
311
317
|
elif logger or isinstance(errors, list):
|
|
312
318
|
err_msg: str = f"User '{user_id}' not authenticated with JusBR"
|
|
@@ -377,9 +383,9 @@ def __get_user_data(user_id: str,
|
|
|
377
383
|
def __post_jusbr(user_data: dict[str, Any],
|
|
378
384
|
body_data: dict[str, Any],
|
|
379
385
|
errors: list[str] | None,
|
|
380
|
-
logger: Logger | None) -> None:
|
|
386
|
+
logger: Logger | None) -> str | None:
|
|
381
387
|
"""
|
|
382
|
-
Send a POST request to JusBR to obtain the authentication
|
|
388
|
+
Send a POST request to JusBR to obtain the authentication token data, and return the access token.
|
|
383
389
|
|
|
384
390
|
For code for token exchange, *body_data* will have the attributes
|
|
385
391
|
- "grant_type": "authorization_code"
|
|
@@ -396,9 +402,13 @@ def __post_jusbr(user_data: dict[str, Any],
|
|
|
396
402
|
:param body_data: the data to send in the body of the request
|
|
397
403
|
:param errors: incidental errors
|
|
398
404
|
:param logger: optional logger
|
|
405
|
+
:return: the access token obtained, or *None* if error
|
|
399
406
|
"""
|
|
400
407
|
global _jusbr_registry
|
|
401
408
|
|
|
409
|
+
# initialize the return variable
|
|
410
|
+
result: str | None = None
|
|
411
|
+
|
|
402
412
|
# complete the data to send in body of request
|
|
403
413
|
body_data["client_id"] = _jusbr_registry.get("client-id")
|
|
404
414
|
client_secret: str = _jusbr_registry.get("client-secret")
|
|
@@ -449,3 +459,5 @@ def __post_jusbr(user_data: dict[str, Any],
|
|
|
449
459
|
errors.append(err_msg)
|
|
450
460
|
if logger:
|
|
451
461
|
logger.error(msg=err_msg)
|
|
462
|
+
|
|
463
|
+
return result
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|