Skip to content

Commit 5c4c146

Browse files
committed
Let deprecated InternalRequest and InternalResponse classes handle deserialization themselves
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent e43104d commit 5c4c146

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/satosa/deprecated.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from saml2.saml import NAMEID_FORMAT_EMAILADDRESS
88
from saml2.saml import NAMEID_FORMAT_UNSPECIFIED
99

10+
from satosa.internal import AuthenticationInformation as _AuthenticationInformation
1011
from satosa.internal import InternalData as _InternalData
1112
from satosa import util
1213

@@ -27,6 +28,14 @@ def __init__(self, user_id_hash_type, requester, requester_name=None):
2728
requester_name=requester_name,
2829
)
2930

31+
@classmethod
32+
def from_dict(cls, data):
33+
instance = cls(
34+
user_id_hash_type=data.get("hash_type"),
35+
requester=data.get("requester"),
36+
requester_name=data.get("requester_name"),
37+
)
38+
return instance
3039

3140

3241
class InternalResponse(_InternalData):
@@ -36,8 +45,25 @@ def __init__(self, auth_info=None):
3645
" Use satosa.internal.InternalData class instead."
3746
)
3847
_warnings.warn(msg, DeprecationWarning)
48+
auth_info = auth_info or _AuthenticationInformation()
3949
super().__init__(auth_info=auth_info)
4050

51+
@classmethod
52+
def from_dict(cls, data):
53+
"""
54+
:type data: dict[str, dict[str, str] | str]
55+
:rtype: satosa.internal_data.InternalResponse
56+
:param data: A dict representation of an InternalResponse object
57+
:return: An InternalResponse object
58+
"""
59+
auth_info = _AuthenticationInformation.from_dict(data.get("auth_info"))
60+
instance = cls(auth_info=auth_info)
61+
instance.user_id_hash_type = data.get("hash_type")
62+
instance.attributes = data.get("attributes", {})
63+
instance.user_id = data.get("user_id")
64+
instance.requester = data.get("requester")
65+
return instance
66+
4167

4268
class SAMLInternalResponse(InternalResponse):
4369
"""

0 commit comments

Comments
 (0)