Skip to content

Commit 56a4799

Browse files
authored
Merge pull request #101 from IdentityPython/dump_load
Dump load
2 parents 677c150 + 3cc2824 commit 56a4799

File tree

13 files changed

+134
-113
lines changed

13 files changed

+134
-113
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"keys": [{"kty": "oct", "use": "enc", "kid": "enc", "k": "GCizp3ewVRV0VZEef3VQwFve7n2QwAFI"}, {"kty": "oct", "use": "sig", "kid": "sig", "k": "QC2JxpVJXPDMpYv_h76jIrt_lA1P4KSu"}]}
1+
{"keys": [{"kty": "oct", "use": "enc", "kid": "enc", "k": "GEmhZ9UKLSq60zECQRyAtmMLG5smRpCl"}, {"kty": "oct", "use": "sig", "kid": "sig", "k": "Px8EGB-oWk-DfMlYWXBHTjED372mvtBt"}]}

src/idpyoidc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Roland Hedberg"
2-
__version__ = "4.1.0"
2+
__version__ = "4.2.0"
33

44
VERIFIED_CLAIM_PREFIX = "__verified"
55

src/idpyoidc/impexp.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ def dump_attr(self, cls, item, exclude_attributes: Optional[List[str]] = None) -
4646
elif cls == b"":
4747
val = f"BYTES:{base64.b64encode(item).decode('utf-8')}"
4848
elif cls == {} and isinstance(item, dict):
49-
val = {k: self.dump_attr(type2cls(v), v, exclude_attributes) for k, v in item.items()}
49+
val = {}
50+
for k, v in item.items():
51+
if k != "upstream_get":
52+
if k == "class":
53+
if isinstance(v, str):
54+
val[k] = v
55+
else:
56+
val[k] = fully_qualified_name(v)
57+
else:
58+
val[k] = self.dump_attr(type2cls(v), v, exclude_attributes)
5059
elif cls == [] and isinstance(item, list):
5160
val = [self.dump_attr(type2cls(v), v, exclude_attributes) for v in item]
5261
elif cls == "DICT_TYPE":
@@ -161,7 +170,6 @@ def load_attr(
161170
return val
162171

163172
def load(self, item: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None):
164-
165173
if load_args:
166174
_kwargs = {"load_args": load_args}
167175
_load_args = load_args
@@ -180,6 +188,20 @@ def load(self, item: dict, init_args: Optional[dict] = None, load_args: Optional
180188
if attr not in item or attr in self.special_load_dump:
181189
continue
182190

191+
_cls_init_args = getattr(cls, "init_args", {})
192+
193+
for param, target in {"upstream_get": "unit_get", "conf": "conf",
194+
"token_handler_args": "token_handler_args"}.items():
195+
target_val = getattr(self, target, None)
196+
if not target_val:
197+
continue
198+
199+
if param in _cls_init_args and param not in _kwargs:
200+
if _kwargs["init_args"] is None:
201+
_kwargs["init_args"] = {param: target_val}
202+
else:
203+
_kwargs["init_args"][param] = target_val
204+
183205
setattr(self, attr, self.load_attr(cls, item[attr], **_kwargs))
184206

185207
for attr, func in self.special_load_dump.items():

src/idpyoidc/server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def do_endpoints(conf, upstream_get):
3232

3333

3434
class Server(Unit):
35-
parameter = {"endpoint": [Endpoint], "context": EndpointContext}
35+
parameter = {"context": EndpointContext}
3636

3737
def __init__(
3838
self,

src/idpyoidc/server/endpoint_context.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from cryptojwt import KeyJar
99
from jinja2 import Environment
1010
from jinja2 import FileSystemLoader
11+
from requests import request
1112

1213
from idpyoidc.context import OidcContext
1314
from idpyoidc.server import authz
@@ -19,13 +20,11 @@
1920
from idpyoidc.server.scopes import SCOPE2CLAIMS
2021
from idpyoidc.server.scopes import Scopes
2122
from idpyoidc.server.session.manager import SessionManager
22-
from idpyoidc.server.session.manager import create_session_manager
2323
from idpyoidc.server.template_handler import Jinja2TemplateHandler
2424
from idpyoidc.server.user_authn.authn_context import populate_authn_broker
2525
from idpyoidc.server.util import get_http_params
2626
from idpyoidc.util import importer
2727
from idpyoidc.util import rndstr
28-
from requests import request
2928

3029
logger = logging.getLogger(__name__)
3130

@@ -61,14 +60,14 @@ def get_token_handler_args(conf: dict) -> dict:
6160
:param conf: The configuration
6261
:rtype: dict
6362
"""
64-
th_args = conf.get("token_handler_args", None)
65-
if not th_args:
66-
th_args = {
63+
token_handler_args = conf.get("token_handler_args", None)
64+
if not token_handler_args:
65+
token_handler_args = {
6766
typ: {"lifetime": tid}
6867
for typ, tid in [("code", 600), ("token", 3600), ("refresh", 86400)]
6968
}
7069

71-
return th_args
70+
return token_handler_args
7271

7372

7473
class EndpointContext(OidcContext):
@@ -88,7 +87,7 @@ class EndpointContext(OidcContext):
8887
"jwks_uri": "",
8988
"keyjar": KeyJar,
9089
"login_hint_lookup": None,
91-
"login_hint2acrs": {},
90+
"login_hint2acrs": None,
9291
"par_db": {},
9392
"provider_info": {},
9493
"registration_access_token": {},
@@ -102,19 +101,19 @@ class EndpointContext(OidcContext):
102101
"client_authn_method": {},
103102
}
104103

105-
init_args = ["upstream_get", "handler"]
104+
init_args = ["upstream_get", "conf"]
106105

107106
def __init__(
108-
self,
109-
conf: Union[dict, OPConfiguration],
110-
upstream_get: Callable,
111-
cwd: Optional[str] = "",
112-
cookie_handler: Optional[Any] = None,
113-
httpc: Optional[Any] = None,
114-
server_type: Optional[str] = "",
115-
entity_id: Optional[str] = "",
116-
keyjar: Optional[KeyJar] = None,
117-
claims_class: Optional[Claims] = None,
107+
self,
108+
conf: Union[dict, OPConfiguration],
109+
upstream_get: Callable,
110+
cwd: Optional[str] = "",
111+
cookie_handler: Optional[Any] = None,
112+
httpc: Optional[Any] = None,
113+
server_type: Optional[str] = "",
114+
entity_id: Optional[str] = "",
115+
keyjar: Optional[KeyJar] = None,
116+
claims_class: Optional[Claims] = None,
118117
):
119118
_id = entity_id or conf.get("issuer", "")
120119
OidcContext.__init__(self, conf, entity_id=_id)
@@ -185,7 +184,7 @@ def __init__(
185184
except KeyError:
186185
pass
187186

188-
self.th_args = get_token_handler_args(conf)
187+
self.token_handler_args = get_token_handler_args(conf)
189188

190189
# session db
191190
self._sub_func = {}
@@ -249,12 +248,11 @@ def __init__(
249248

250249
self.setup_authentication()
251250

252-
self.session_manager = create_session_manager(
253-
self.unit_get,
254-
self.th_args,
251+
self.session_manager = SessionManager(
252+
self.token_handler_args,
255253
sub_func=self._sub_func,
256-
conf=self.conf,
257-
)
254+
conf=conf,
255+
upstream_get=self.unit_get)
258256

259257
self.do_userinfo()
260258

@@ -276,7 +274,8 @@ def setup_authz(self):
276274
return authz.Implicit(self.unit_get)
277275

278276
def setup_client_authn_methods(self):
279-
self.client_authn_methods = client_auth_setup(self.unit_get, self.conf.get("client_authn_methods"))
277+
self.client_authn_methods = client_auth_setup(self.unit_get,
278+
self.conf.get("client_authn_methods"))
280279

281280
def setup_login_hint_lookup(self):
282281
_conf = self.conf.get("login_hint_lookup")

0 commit comments

Comments
 (0)