Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump load #101

Merged
merged 8 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/flask_op/private/cookie_jwks.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"keys": [{"kty": "oct", "use": "enc", "kid": "enc", "k": "GCizp3ewVRV0VZEef3VQwFve7n2QwAFI"}, {"kty": "oct", "use": "sig", "kid": "sig", "k": "QC2JxpVJXPDMpYv_h76jIrt_lA1P4KSu"}]}
{"keys": [{"kty": "oct", "use": "enc", "kid": "enc", "k": "GEmhZ9UKLSq60zECQRyAtmMLG5smRpCl"}, {"kty": "oct", "use": "sig", "kid": "sig", "k": "Px8EGB-oWk-DfMlYWXBHTjED372mvtBt"}]}
2 changes: 1 addition & 1 deletion src/idpyoidc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "Roland Hedberg"
__version__ = "4.1.0"
__version__ = "4.2.0"

VERIFIED_CLAIM_PREFIX = "__verified"

Expand Down
26 changes: 24 additions & 2 deletions src/idpyoidc/impexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ def dump_attr(self, cls, item, exclude_attributes: Optional[List[str]] = None) -
elif cls == b"":
val = f"BYTES:{base64.b64encode(item).decode('utf-8')}"
elif cls == {} and isinstance(item, dict):
val = {k: self.dump_attr(type2cls(v), v, exclude_attributes) for k, v in item.items()}
val = {}
for k, v in item.items():
if k != "upstream_get":
if k == "class":
if isinstance(v, str):
val[k] = v
else:
val[k] = fully_qualified_name(v)
else:
val[k] = self.dump_attr(type2cls(v), v, exclude_attributes)
elif cls == [] and isinstance(item, list):
val = [self.dump_attr(type2cls(v), v, exclude_attributes) for v in item]
elif cls == "DICT_TYPE":
Expand Down Expand Up @@ -161,7 +170,6 @@ def load_attr(
return val

def load(self, item: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None):

if load_args:
_kwargs = {"load_args": load_args}
_load_args = load_args
Expand All @@ -180,6 +188,20 @@ def load(self, item: dict, init_args: Optional[dict] = None, load_args: Optional
if attr not in item or attr in self.special_load_dump:
continue

_cls_init_args = getattr(cls, "init_args", {})

for param, target in {"upstream_get": "unit_get", "conf": "conf",
"token_handler_args": "token_handler_args"}.items():
target_val = getattr(self, target, None)
if not target_val:
continue

if param in _cls_init_args and param not in _kwargs:
if _kwargs["init_args"] is None:
_kwargs["init_args"] = {param: target_val}
else:
_kwargs["init_args"][param] = target_val

setattr(self, attr, self.load_attr(cls, item[attr], **_kwargs))

for attr, func in self.special_load_dump.items():
Expand Down
2 changes: 1 addition & 1 deletion src/idpyoidc/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def do_endpoints(conf, upstream_get):


class Server(Unit):
parameter = {"endpoint": [Endpoint], "context": EndpointContext}
parameter = {"context": EndpointContext}

def __init__(
self,
Expand Down
49 changes: 24 additions & 25 deletions src/idpyoidc/server/endpoint_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cryptojwt import KeyJar
from jinja2 import Environment
from jinja2 import FileSystemLoader
from requests import request

from idpyoidc.context import OidcContext
from idpyoidc.server import authz
Expand All @@ -19,13 +20,11 @@
from idpyoidc.server.scopes import SCOPE2CLAIMS
from idpyoidc.server.scopes import Scopes
from idpyoidc.server.session.manager import SessionManager
from idpyoidc.server.session.manager import create_session_manager
from idpyoidc.server.template_handler import Jinja2TemplateHandler
from idpyoidc.server.user_authn.authn_context import populate_authn_broker
from idpyoidc.server.util import get_http_params
from idpyoidc.util import importer
from idpyoidc.util import rndstr
from requests import request

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,14 +60,14 @@ def get_token_handler_args(conf: dict) -> dict:
:param conf: The configuration
:rtype: dict
"""
th_args = conf.get("token_handler_args", None)
if not th_args:
th_args = {
token_handler_args = conf.get("token_handler_args", None)
if not token_handler_args:
token_handler_args = {
typ: {"lifetime": tid}
for typ, tid in [("code", 600), ("token", 3600), ("refresh", 86400)]
}

return th_args
return token_handler_args


class EndpointContext(OidcContext):
Expand All @@ -88,7 +87,7 @@ class EndpointContext(OidcContext):
"jwks_uri": "",
"keyjar": KeyJar,
"login_hint_lookup": None,
"login_hint2acrs": {},
"login_hint2acrs": None,
"par_db": {},
"provider_info": {},
"registration_access_token": {},
Expand All @@ -102,19 +101,19 @@ class EndpointContext(OidcContext):
"client_authn_method": {},
}

init_args = ["upstream_get", "handler"]
init_args = ["upstream_get", "conf"]

def __init__(
self,
conf: Union[dict, OPConfiguration],
upstream_get: Callable,
cwd: Optional[str] = "",
cookie_handler: Optional[Any] = None,
httpc: Optional[Any] = None,
server_type: Optional[str] = "",
entity_id: Optional[str] = "",
keyjar: Optional[KeyJar] = None,
claims_class: Optional[Claims] = None,
self,
conf: Union[dict, OPConfiguration],
upstream_get: Callable,
cwd: Optional[str] = "",
cookie_handler: Optional[Any] = None,
httpc: Optional[Any] = None,
server_type: Optional[str] = "",
entity_id: Optional[str] = "",
keyjar: Optional[KeyJar] = None,
claims_class: Optional[Claims] = None,
):
_id = entity_id or conf.get("issuer", "")
OidcContext.__init__(self, conf, entity_id=_id)
Expand Down Expand Up @@ -185,7 +184,7 @@ def __init__(
except KeyError:
pass

self.th_args = get_token_handler_args(conf)
self.token_handler_args = get_token_handler_args(conf)

# session db
self._sub_func = {}
Expand Down Expand Up @@ -249,12 +248,11 @@ def __init__(

self.setup_authentication()

self.session_manager = create_session_manager(
self.unit_get,
self.th_args,
self.session_manager = SessionManager(
self.token_handler_args,
sub_func=self._sub_func,
conf=self.conf,
)
conf=conf,
upstream_get=self.unit_get)

self.do_userinfo()

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

def setup_client_authn_methods(self):
self.client_authn_methods = client_auth_setup(self.unit_get, self.conf.get("client_authn_methods"))
self.client_authn_methods = client_auth_setup(self.unit_get,
self.conf.get("client_authn_methods"))

def setup_login_hint_lookup(self):
_conf = self.conf.get("login_hint_lookup")
Expand Down
Loading
Loading