pypomes-iam 0.5.7__py3-none-any.whl → 0.5.8__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.
- pypomes_iam/__init__.py +7 -12
- pypomes_iam/iam_actions.py +357 -47
- pypomes_iam/iam_common.py +165 -49
- pypomes_iam/iam_pomes.py +130 -0
- pypomes_iam/iam_services.py +7 -7
- pypomes_iam/provider_pomes.py +46 -26
- pypomes_iam/token_pomes.py +0 -2
- {pypomes_iam-0.5.7.dist-info → pypomes_iam-0.5.8.dist-info}/METADATA +1 -1
- pypomes_iam-0.5.8.dist-info/RECORD +11 -0
- pypomes_iam/jusbr_pomes.py +0 -125
- pypomes_iam/keycloak_pomes.py +0 -136
- pypomes_iam-0.5.7.dist-info/RECORD +0 -12
- {pypomes_iam-0.5.7.dist-info → pypomes_iam-0.5.8.dist-info}/WHEEL +0 -0
- {pypomes_iam-0.5.7.dist-info → pypomes_iam-0.5.8.dist-info}/licenses/LICENSE +0 -0
pypomes_iam/jusbr_pomes.py
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
from cachetools import Cache, FIFOCache
|
|
2
|
-
from flask import Flask
|
|
3
|
-
from logging import Logger
|
|
4
|
-
from pypomes_core import (
|
|
5
|
-
APP_PREFIX, env_get_int, env_get_str
|
|
6
|
-
)
|
|
7
|
-
from typing import Any, Final
|
|
8
|
-
|
|
9
|
-
from .iam_common import _IAM_SERVERS, IamServer, _iam_lock
|
|
10
|
-
from .iam_actions import action_token
|
|
11
|
-
|
|
12
|
-
JUSBR_CLIENT_ID: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CLIENT_ID")
|
|
13
|
-
JUSBR_CLIENT_SECRET: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_CLIENT_SECRET")
|
|
14
|
-
JUSBR_CLIENT_TIMEOUT: Final[int] = env_get_int(key=f"{APP_PREFIX}_JUSBR_CLIENT_TIMEOUT")
|
|
15
|
-
|
|
16
|
-
JUSBR_ENDPOINT_CALLBACK: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_CALLBACK",
|
|
17
|
-
def_value="/iam/jusbr:callback")
|
|
18
|
-
JUSBR_ENDPOINT_LOGIN: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_LOGIN",
|
|
19
|
-
def_value="/iam/jusbr:login")
|
|
20
|
-
JUSBR_ENDPOINT_LOGOUT: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_LOGOUT",
|
|
21
|
-
def_value="/iam/jusbr:logout")
|
|
22
|
-
JUSBR_ENDPOINT_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_ENDPOINT_TOKEN",
|
|
23
|
-
def_value="/iam/jusbr:get-token")
|
|
24
|
-
|
|
25
|
-
JUSBR_PUBLIC_KEY_LIFETIME: Final[int] = env_get_int(key=f"{APP_PREFIX}_JUSBR_PUBLIC_KEY_LIFETIME",
|
|
26
|
-
def_value=86400) # 24 hours
|
|
27
|
-
JUSBR_REALM: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_REALM")
|
|
28
|
-
JUSBR_RECIPIENT_ATTR: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_RECIPIENT_ATTR",
|
|
29
|
-
def_value="preferred_username")
|
|
30
|
-
JUSBR_URL_AUTH_BASE: Final[str] = env_get_str(key=f"{APP_PREFIX}_JUSBR_URL_AUTH_BASE")
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def jusbr_setup(flask_app: Flask,
|
|
34
|
-
base_url: str = JUSBR_URL_AUTH_BASE,
|
|
35
|
-
realm: str = JUSBR_REALM,
|
|
36
|
-
client_id: str = JUSBR_CLIENT_ID,
|
|
37
|
-
client_secret: str = JUSBR_CLIENT_SECRET,
|
|
38
|
-
client_timeout: int = JUSBR_CLIENT_TIMEOUT,
|
|
39
|
-
public_key_lifetime: int | None = JUSBR_PUBLIC_KEY_LIFETIME,
|
|
40
|
-
recipient_attribute: str | None = JUSBR_RECIPIENT_ATTR,
|
|
41
|
-
callback_endpoint: str | None = JUSBR_ENDPOINT_CALLBACK,
|
|
42
|
-
login_endpoint: str | None = JUSBR_ENDPOINT_LOGIN,
|
|
43
|
-
logout_endpoint: str | None = JUSBR_ENDPOINT_LOGOUT,
|
|
44
|
-
token_endpoint: str | None = JUSBR_ENDPOINT_TOKEN) -> None:
|
|
45
|
-
"""
|
|
46
|
-
Configure the JusBR IAM.
|
|
47
|
-
|
|
48
|
-
This should be invoked only once, before the first access to a JusBR service.
|
|
49
|
-
|
|
50
|
-
:param flask_app: the Flask application
|
|
51
|
-
:param base_url: base URL to request JusBR services
|
|
52
|
-
:param realm: the JusBR realm
|
|
53
|
-
:param client_id: the client's identification with JusBR
|
|
54
|
-
:param client_secret: the client's password with JusBR
|
|
55
|
-
:param client_timeout: timeout for login authentication (in seconds,defaults to no timeout)
|
|
56
|
-
:param public_key_lifetime: how long to use JusBR's public key, before refreshing it (in seconds)
|
|
57
|
-
:param recipient_attribute: attribute in the token's payload holding the token's subject
|
|
58
|
-
:param callback_endpoint: endpoint for the callback from JusBR
|
|
59
|
-
:param login_endpoint: endpoint for redirecting user to JusBR's login page
|
|
60
|
-
:param logout_endpoint: endpoint for terminating user access to JusBR
|
|
61
|
-
:param token_endpoint: endpoint for retrieving JusBR's authentication token
|
|
62
|
-
"""
|
|
63
|
-
from .iam_services import service_login, service_logout, service_callback, service_token
|
|
64
|
-
|
|
65
|
-
# configure the JusBR registry
|
|
66
|
-
cache: Cache = FIFOCache(maxsize=1048576)
|
|
67
|
-
cache["users"] = {}
|
|
68
|
-
with _iam_lock:
|
|
69
|
-
_IAM_SERVERS[IamServer.IAM_JUSRBR] = {
|
|
70
|
-
"base-url": f"{base_url}/realms/{realm}",
|
|
71
|
-
"client-id": client_id,
|
|
72
|
-
"client-secret": client_secret,
|
|
73
|
-
"client-timeout": client_timeout,
|
|
74
|
-
"public-key": None,
|
|
75
|
-
"pk-lifetime": public_key_lifetime,
|
|
76
|
-
"pk-expiration": 0,
|
|
77
|
-
"recipient-attr": recipient_attribute,
|
|
78
|
-
"cache": cache
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
# establish the endpoints
|
|
82
|
-
if callback_endpoint:
|
|
83
|
-
flask_app.add_url_rule(rule=callback_endpoint,
|
|
84
|
-
endpoint="jusbr-callback",
|
|
85
|
-
view_func=service_callback,
|
|
86
|
-
methods=["GET"])
|
|
87
|
-
if login_endpoint:
|
|
88
|
-
flask_app.add_url_rule(rule=login_endpoint,
|
|
89
|
-
endpoint="jusbr-login",
|
|
90
|
-
view_func=service_login,
|
|
91
|
-
methods=["GET"])
|
|
92
|
-
if logout_endpoint:
|
|
93
|
-
flask_app.add_url_rule(rule=logout_endpoint,
|
|
94
|
-
endpoint="jusbr-logout",
|
|
95
|
-
view_func=service_logout,
|
|
96
|
-
methods=["GET"])
|
|
97
|
-
if token_endpoint:
|
|
98
|
-
flask_app.add_url_rule(rule=token_endpoint,
|
|
99
|
-
endpoint="jusbr-token",
|
|
100
|
-
view_func=service_token,
|
|
101
|
-
methods=["GET"])
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def jusbr_get_token(user_id: str,
|
|
105
|
-
errors: list[str] = None,
|
|
106
|
-
logger: Logger = None) -> str:
|
|
107
|
-
"""
|
|
108
|
-
Retrieve a JusBR authentication token for *user_id*.
|
|
109
|
-
|
|
110
|
-
:param user_id: the user's identification
|
|
111
|
-
:param errors: incidental errors
|
|
112
|
-
:param logger: optional logger
|
|
113
|
-
:return: the uthentication tokem
|
|
114
|
-
"""
|
|
115
|
-
# declare the return variable
|
|
116
|
-
result: str
|
|
117
|
-
|
|
118
|
-
# retrieve the token
|
|
119
|
-
args: dict[str, Any] = {"user-id": user_id}
|
|
120
|
-
with _iam_lock:
|
|
121
|
-
result = action_token(iam_server=IamServer.IAM_JUSRBR,
|
|
122
|
-
args=args,
|
|
123
|
-
errors=errors,
|
|
124
|
-
logger=logger)
|
|
125
|
-
return result
|
pypomes_iam/keycloak_pomes.py
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
from cachetools import Cache, FIFOCache
|
|
2
|
-
from flask import Flask
|
|
3
|
-
from logging import Logger
|
|
4
|
-
from pypomes_core import (
|
|
5
|
-
APP_PREFIX, env_get_int, env_get_str
|
|
6
|
-
)
|
|
7
|
-
from typing import Any, Final
|
|
8
|
-
|
|
9
|
-
from .iam_common import _IAM_SERVERS, IamServer, _iam_lock
|
|
10
|
-
from .iam_actions import action_token
|
|
11
|
-
|
|
12
|
-
KEYCLOAK_CLIENT_ID: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_CLIENT_ID")
|
|
13
|
-
KEYCLOAK_CLIENT_SECRET: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_CLIENT_SECRET")
|
|
14
|
-
KEYCLOAK_CLIENT_TIMEOUT: Final[int] = env_get_int(key=f"{APP_PREFIX}_KEYCLOAK_CLIENT_TIMEOUT")
|
|
15
|
-
|
|
16
|
-
KEYCLOAK_ENDPOINT_CALLBACK: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_ENDPOINT_CALLBACK",
|
|
17
|
-
def_value="/iam/ijud:callback")
|
|
18
|
-
KEYCLOAK_ENDPOINT_EXCHANGE: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_ENDPOINT_EXCHANGE",
|
|
19
|
-
def_value="/iam/ijud:exchange-token")
|
|
20
|
-
KEYCLOAK_ENDPOINT_LOGIN: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_ENDPOINT_LOGIN",
|
|
21
|
-
def_value="/iam/ijud:login")
|
|
22
|
-
KEYCLOAK_ENDPOINT_LOGOUT: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_ENDPOINT_LOGOUT",
|
|
23
|
-
def_value="/iam/ijud:logout")
|
|
24
|
-
KEYCLOAK_ENDPOINT_TOKEN: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_ENDPOINT_TOKEN",
|
|
25
|
-
def_value="/iam/ijud:get-token")
|
|
26
|
-
|
|
27
|
-
KEYCLOAK_PUBLIC_KEY_LIFETIME: Final[int] = env_get_int(key=f"{APP_PREFIX}_KEYCLOAK_PUBLIC_KEY_LIFETIME",
|
|
28
|
-
def_value=86400) # 24 hours
|
|
29
|
-
KEYCLOAK_REALM: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_REALM")
|
|
30
|
-
KEYCLOAK_RECIPIENT_ATTR: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_RECIPIENT_ATTR",
|
|
31
|
-
def_value="preferred_username")
|
|
32
|
-
KEYCLOAK_URL_AUTH_BASE: Final[str] = env_get_str(key=f"{APP_PREFIX}_KEYCLOAK_URL_AUTH_BASE")
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def keycloak_setup(flask_app: Flask,
|
|
36
|
-
base_url: str = KEYCLOAK_URL_AUTH_BASE,
|
|
37
|
-
realm: str = KEYCLOAK_REALM,
|
|
38
|
-
client_id: str = KEYCLOAK_CLIENT_ID,
|
|
39
|
-
client_secret: str = KEYCLOAK_CLIENT_SECRET,
|
|
40
|
-
client_timeout: int = KEYCLOAK_CLIENT_TIMEOUT,
|
|
41
|
-
public_key_lifetime: int | None = KEYCLOAK_PUBLIC_KEY_LIFETIME,
|
|
42
|
-
recipient_attribute: str | None = KEYCLOAK_RECIPIENT_ATTR,
|
|
43
|
-
callback_endpoint: str | None = KEYCLOAK_ENDPOINT_CALLBACK,
|
|
44
|
-
login_endpoint: str | None = KEYCLOAK_ENDPOINT_LOGIN,
|
|
45
|
-
logout_endpoint: str | None = KEYCLOAK_ENDPOINT_LOGOUT,
|
|
46
|
-
token_endpoint: str | None = KEYCLOAK_ENDPOINT_TOKEN,
|
|
47
|
-
exchange_endpoint: str | None = KEYCLOAK_ENDPOINT_EXCHANGE) -> None:
|
|
48
|
-
"""
|
|
49
|
-
Configure the Keycloak IAM.
|
|
50
|
-
|
|
51
|
-
This should be invoked only once, before the first access to a Keycloak service.
|
|
52
|
-
|
|
53
|
-
:param flask_app: the Flask application
|
|
54
|
-
:param base_url: base URL to request Keycloak services
|
|
55
|
-
:param realm: the Keycloak realm
|
|
56
|
-
:param client_id: the client's identification with JusBR
|
|
57
|
-
:param client_secret: the client's password with JusBR
|
|
58
|
-
:param client_timeout: timeout for login authentication (in seconds,defaults to no timeout)
|
|
59
|
-
:param public_key_lifetime: how long to use Keycloak's public key, before refreshing it (in seconds)
|
|
60
|
-
:param recipient_attribute: attribute in the token's payload holding the token's subject
|
|
61
|
-
:param callback_endpoint: endpoint for the callback from the front end
|
|
62
|
-
:param login_endpoint: endpoint for redirecting user to Keycloak's login page
|
|
63
|
-
:param logout_endpoint: endpoint for terminating user access to Keycloak
|
|
64
|
-
:param token_endpoint: endpoint for retrieving Keycloak's authentication token
|
|
65
|
-
:param exchange_endpoint: endpoint for requesting token exchange
|
|
66
|
-
"""
|
|
67
|
-
from .iam_services import (
|
|
68
|
-
service_login, service_logout, service_callback, service_exchange, service_token
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
# configure the Keycloak registry
|
|
72
|
-
cache: Cache = FIFOCache(maxsize=1048576)
|
|
73
|
-
cache["users"] = {}
|
|
74
|
-
with _iam_lock:
|
|
75
|
-
_IAM_SERVERS[IamServer.IAM_KEYCLOAK] = {
|
|
76
|
-
"base-url": f"{base_url}/realms/{realm}",
|
|
77
|
-
"client-id": client_id,
|
|
78
|
-
"client-secret": client_secret,
|
|
79
|
-
"client-timeout": client_timeout,
|
|
80
|
-
"public-key": None,
|
|
81
|
-
"pk-lifetime": public_key_lifetime,
|
|
82
|
-
"pk-expiration": 0,
|
|
83
|
-
"recipient-attr": recipient_attribute,
|
|
84
|
-
"cache": cache
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
# establish the endpoints
|
|
88
|
-
if callback_endpoint:
|
|
89
|
-
flask_app.add_url_rule(rule=callback_endpoint,
|
|
90
|
-
endpoint="keycloak-callback",
|
|
91
|
-
view_func=service_callback,
|
|
92
|
-
methods=["GET"])
|
|
93
|
-
if login_endpoint:
|
|
94
|
-
flask_app.add_url_rule(rule=login_endpoint,
|
|
95
|
-
endpoint="keycloak-login",
|
|
96
|
-
view_func=service_login,
|
|
97
|
-
methods=["GET"])
|
|
98
|
-
if logout_endpoint:
|
|
99
|
-
flask_app.add_url_rule(rule=logout_endpoint,
|
|
100
|
-
endpoint="keycloak-logout",
|
|
101
|
-
view_func=service_logout,
|
|
102
|
-
methods=["GET"])
|
|
103
|
-
if token_endpoint:
|
|
104
|
-
flask_app.add_url_rule(rule=token_endpoint,
|
|
105
|
-
endpoint="keycloak-token",
|
|
106
|
-
view_func=service_token,
|
|
107
|
-
methods=["GET"])
|
|
108
|
-
if exchange_endpoint:
|
|
109
|
-
flask_app.add_url_rule(rule=exchange_endpoint,
|
|
110
|
-
endpoint="keycloak-exchange",
|
|
111
|
-
view_func=service_exchange,
|
|
112
|
-
methods=["POST"])
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def keycloak_get_token(user_id: str,
|
|
116
|
-
errors: list[str] = None,
|
|
117
|
-
logger: Logger = None) -> str:
|
|
118
|
-
"""
|
|
119
|
-
Retrieve a Keycloak authentication token for *user_id*.
|
|
120
|
-
|
|
121
|
-
:param user_id: the user's identification
|
|
122
|
-
:param errors: incidental errors
|
|
123
|
-
:param logger: optional logger
|
|
124
|
-
:return: the uthentication tokem
|
|
125
|
-
"""
|
|
126
|
-
# declare the return variable
|
|
127
|
-
result: str
|
|
128
|
-
|
|
129
|
-
# retrieve the token
|
|
130
|
-
args: dict[str, Any] = {"user-id": user_id}
|
|
131
|
-
with _iam_lock:
|
|
132
|
-
result = action_token(iam_server=IamServer.IAM_KEYCLOAK,
|
|
133
|
-
args=args,
|
|
134
|
-
errors=errors,
|
|
135
|
-
logger=logger)
|
|
136
|
-
return result
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
pypomes_iam/__init__.py,sha256=GwGK4486tfVD47a4FDiIG6Xl2UeZAKqWUNDauolQNao,1125
|
|
2
|
-
pypomes_iam/iam_actions.py,sha256=0x5kPaDor2rHiOznyF9DLzsNRGLleB66K6RJBPaJkBc,24178
|
|
3
|
-
pypomes_iam/iam_common.py,sha256=yHkbGZb-bSa3sq4UHs1GW4R4474BPTItVm9-J3dd3Bc,12712
|
|
4
|
-
pypomes_iam/iam_services.py,sha256=iq0BQ4sHikPJPiVMv3-q6cYfZVSCxauVkpQilaiSUR8,15783
|
|
5
|
-
pypomes_iam/jusbr_pomes.py,sha256=X_YgY45122tflAzQdAMEcEyVbPvzFigjHLal0qL1v_M,5916
|
|
6
|
-
pypomes_iam/keycloak_pomes.py,sha256=FGdkPjVGEDp5Pwfav4EIc9uSbT4_pG7oPqaiHeJBSLU,6763
|
|
7
|
-
pypomes_iam/provider_pomes.py,sha256=CdEjYjepGXsehn_ujljUQKs0Ws7xNOzBYG6wKp9C7-E,7233
|
|
8
|
-
pypomes_iam/token_pomes.py,sha256=Bz9pT2oU6jTEr_ZEZEJ3kUjH3TfxRyY1_vR319v6CEo,6692
|
|
9
|
-
pypomes_iam-0.5.7.dist-info/METADATA,sha256=tX2E2pV3KcLsdMOH6YJpL6DYQyfdVcg1iA1tI2O5cpk,694
|
|
10
|
-
pypomes_iam-0.5.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
-
pypomes_iam-0.5.7.dist-info/licenses/LICENSE,sha256=YvUELgV8qvXlaYsy9hXG5EW3Bmsrkw-OJmmILZnonAc,1086
|
|
12
|
-
pypomes_iam-0.5.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|