Skip to content

Commit 13e3b5d

Browse files
committed
Refactor internal data representation
Unify internal request and response data. Deprecate internal_data module; use satosa.internal. Deprecate InternalRequest class; use satosa.internal.InternalData. Deprecate InternalResponse class; use satosa.internal.InternalData. Deprecate SAMLInternalResponse class; use satosa.internal.InternalData. Changes in internal data fields: - Deprecate user_id; use subject_id. - Deprecate user_id_hash_type; use subject_type. - Deprecate name_id; use subject_id. - Deprecate approved_attributes; use attributes. All arguments for InternalData are now optional and named. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 3f031e9 commit 13e3b5d

37 files changed

+549
-376
lines changed

src/satosa/backends/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BackendModule(object):
1313
def __init__(self, auth_callback_func, internal_attributes, base_url, name):
1414
"""
1515
:type auth_callback_func:
16-
(satosa.context.Context, satosa.internal_data.InternalResponse) -> satosa.response.Response
16+
(satosa.context.Context, satosa.internal.InternalData) -> satosa.response.Response
1717
:type internal_attributes: dict[string, dict[str, str | list[str]]]
1818
:type base_url: str
1919
:type name: str
@@ -37,7 +37,7 @@ def start_auth(self, context, internal_request):
3737
This is the start up function of the backend authorization.
3838
3939
:type context: satosa.context.Context
40-
:type internal_request: satosa.internal_data.InternalRequest
40+
:type internal_request: satosa.internal.InternalData
4141
:rtype satosa.response.Response
4242
4343
:param context: the request context

src/satosa/backends/github.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from oic.oauth2.message import AuthorizationResponse
1111

1212
from satosa.backends.oauth import _OAuthBackend
13-
from ..internal_data import InternalResponse
14-
from ..internal_data import AuthenticationInformation
15-
from ..response import Redirect
16-
from ..util import rndstr
13+
from satosa.internal import AuthenticationInformation
14+
from satosa.internal import InternalData
15+
from satosa.response import Redirect
16+
from satosa.util import rndstr
1717

1818
logger = logging.getLogger(__name__)
1919

@@ -32,7 +32,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
3232
:param base_url: base url of the service
3333
:param name: name of the plugin
3434
:type outgoing:
35-
(satosa.context.Context, satosa.internal_data.InternalResponse) ->
35+
(satosa.context.Context, satosa.internal.InternalData) ->
3636
satosa.response.Response
3737
:type internal_attributes: dict[string, dict[str, str | list[str]]]
3838
:type config: dict[str, dict[str, str] | list[str] | str]
@@ -51,7 +51,7 @@ def start_auth(self, context, internal_request, get_state=stateID):
5151
5252
:type get_state: Callable[[str, bytes], str]
5353
:type context: satosa.context.Context
54-
:type internal_request: satosa.internal_data.InternalRequest
54+
:type internal_request: satosa.internal.InternalData
5555
:rtype satosa.response.Redirect
5656
"""
5757
oauth_state = get_state(self.config["base_url"], rndstr().encode())
@@ -95,10 +95,10 @@ def _authn_response(self, context):
9595

9696
user_info = self.user_information(response["access_token"])
9797
auth_info = self.auth_info(context.request)
98-
internal_response = InternalResponse(auth_info=auth_info)
98+
internal_response = InternalData(auth_info=auth_info)
9999
internal_response.attributes = self.converter.to_internal(
100100
self.external_type, user_info)
101-
internal_response.user_id = str(user_info[self.user_id_attr])
101+
internal_response.subject_id = str(user_info[self.user_id_attr])
102102
del context.state[self.name]
103103
return self.auth_callback_func(context, internal_response)
104104

src/satosa/backends/linkedin.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
from oic.oauth2.message import AuthorizationResponse
1111

1212
from satosa.backends.oauth import _OAuthBackend
13-
from ..internal_data import InternalResponse
14-
from ..internal_data import AuthenticationInformation
15-
from ..response import Redirect
16-
from ..util import rndstr
13+
from satosa.internal import AuthenticationInformation
14+
from satosa.internal import InternalData
15+
from satosa.response import Redirect
16+
from satosa.util import rndstr
1717

1818

1919
logger = logging.getLogger(__name__)
@@ -33,7 +33,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
3333
:param base_url: base url of the service
3434
:param name: name of the plugin
3535
:type outgoing:
36-
(satosa.context.Context, satosa.internal_data.InternalResponse) ->
36+
(satosa.context.Context, satosa.internal.InternalData) ->
3737
satosa.response.Response
3838
:type internal_attributes: dict[string, dict[str, str | list[str]]]
3939
:type config: dict[str, dict[str, str] | list[str] | str]
@@ -52,7 +52,7 @@ def start_auth(self, context, internal_request, get_state=stateID):
5252
5353
:type get_state: Callable[[str, bytes], str]
5454
:type context: satosa.context.Context
55-
:type internal_request: satosa.internal_data.InternalRequest
55+
:type internal_request: satosa.internal.InternalData
5656
:rtype satosa.response.Redirect
5757
"""
5858
oauth_state = get_state(self.config["base_url"], rndstr().encode())
@@ -96,10 +96,10 @@ def _authn_response(self, context):
9696

9797
user_info = self.user_information(response["access_token"])
9898
auth_info = self.auth_info(context.request)
99-
internal_response = InternalResponse(auth_info=auth_info)
99+
internal_response = InternalData(auth_info=auth_info)
100100
internal_response.attributes = self.converter.to_internal(
101101
self.external_type, user_info)
102-
internal_response.user_id = user_info[self.user_id_attr]
102+
internal_response.subject_id = user_info[self.user_id_attr]
103103
del context.state[self.name]
104104
return self.auth_callback_func(context, internal_response)
105105

src/satosa/backends/oauth.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
from oic.oauth2.message import AuthorizationResponse
1111
from oic.utils.authn.authn_context import UNSPECIFIED
1212

13-
from .base import BackendModule
14-
from ..exception import SATOSAAuthenticationError
15-
from ..internal_data import InternalResponse, AuthenticationInformation
16-
from ..logging_util import satosa_logging
17-
from ..metadata_creation.description import OrganizationDesc, UIInfoDesc, ContactPersonDesc, MetadataDescription
18-
from ..response import Redirect
19-
from ..util import rndstr
13+
from satosa.internal import AuthenticationInformation
14+
from satosa.internal import InternalData
15+
from satosa.exception import SATOSAAuthenticationError
16+
from satosa.logging_util import satosa_logging
17+
from satosa.response import Redirect
18+
from satosa.util import rndstr
19+
from satosa.metadata_creation.description import (
20+
OrganizationDesc, UIInfoDesc, ContactPersonDesc, MetadataDescription
21+
)
22+
from satosa.backends.base import BackendModule
23+
2024

2125
logger = logging.getLogger(__name__)
2226

@@ -40,7 +44,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name, extern
4044
:param external_type: The name for this module in the internal attributes.
4145
4246
:type outgoing:
43-
(satosa.context.Context, satosa.internal_data.InternalResponse) -> satosa.response.Response
47+
(satosa.context.Context, satosa.internal.InternalData) -> satosa.response.Response
4448
:type internal_attributes: dict[string, dict[str, str | list[str]]]
4549
:type config: dict[str, dict[str, str] | list[str]]
4650
:type base_url: str
@@ -67,7 +71,7 @@ def start_auth(self, context, internal_request, get_state=stateID):
6771
6872
:type get_state: Callable[[str, bytes], str]
6973
:type context: satosa.context.Context
70-
:type internal_request: satosa.internal_data.InternalRequest
74+
:type internal_request: satosa.internal.InternalData
7175
:rtype satosa.response.Redirect
7276
"""
7377
oauth_state = get_state(self.config["base_url"], rndstr().encode())
@@ -132,9 +136,9 @@ def _authn_response(self, context):
132136
self._verify_state(atresp, state_data, context.state)
133137

134138
user_info = self.user_information(atresp["access_token"])
135-
internal_response = InternalResponse(auth_info=self.auth_info(context.request))
139+
internal_response = InternalData(auth_info=self.auth_info(context.request))
136140
internal_response.attributes = self.converter.to_internal(self.external_type, user_info)
137-
internal_response.user_id = user_info[self.user_id_attr]
141+
internal_response.subject_id = user_info[self.user_id_attr]
138142
del context.state[self.name]
139143
return self.auth_callback_func(context, internal_response)
140144

@@ -187,7 +191,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
187191
:param name: name of the plugin
188192
189193
:type outgoing:
190-
(satosa.context.Context, satosa.internal_data.InternalResponse) -> satosa.response.Response
194+
(satosa.context.Context, satosa.internal.InternalData) -> satosa.response.Response
191195
:type internal_attributes: dict[string, dict[str, str | list[str]]]
192196
:type config: dict[str, dict[str, str] | list[str] | str]
193197
:type base_url: str

src/satosa/backends/openid_connect.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
from oic.utils.authn.authn_context import UNSPECIFIED
1313
from oic.utils.authn.client import CLIENT_AUTHN_METHOD
1414

15+
from satosa.internal import AuthenticationInformation
16+
from satosa.internal import InternalData
1517
from .base import BackendModule
1618
from .oauth import get_metadata_desc_for_oauth_backend
1719
from ..exception import SATOSAAuthenticationError, SATOSAError
18-
from ..internal_data import InternalResponse, AuthenticationInformation
1920
from ..logging_util import satosa_logging
2021
from ..response import Redirect
2122

@@ -43,7 +44,7 @@ def __init__(self, auth_callback_func, internal_attributes, config, base_url, na
4344
:param name: name of the plugin
4445
4546
:type auth_callback_func:
46-
(satosa.context.Context, satosa.internal_data.InternalResponse) -> satosa.response.Response
47+
(satosa.context.Context, satosa.internal.InternalData) -> satosa.response.Response
4748
:type internal_attributes: dict[string, dict[str, str | list[str]]]
4849
:type config: dict[str, dict[str, str] | list[str]]
4950
:type base_url: str
@@ -62,7 +63,7 @@ def start_auth(self, context, request_info):
6263
"""
6364
See super class method satosa.backends.base#start_auth
6465
:type context: satosa.context.Context
65-
:type request_info: satosa.internal_data.InternalRequest
66+
:type request_info: satosa.internal.InternalData
6667
"""
6768
oidc_nonce = rndstr()
6869
oidc_state = rndstr()
@@ -209,17 +210,17 @@ def _translate_response(self, response, issuer):
209210
:type response: dict[str, str]
210211
:type issuer: str
211212
:type subject_type: str
212-
:rtype: InternalResponse
213+
:rtype: InternalData
213214
214215
:param response: Dictioary with attribute name as key.
215216
:param issuer: The oidc op that gave the repsonse.
216217
:param subject_type: public or pairwise according to oidc standard.
217218
:return: A SATOSA internal response.
218219
"""
219220
auth_info = AuthenticationInformation(UNSPECIFIED, str(datetime.now()), issuer)
220-
internal_resp = InternalResponse(auth_info=auth_info)
221+
internal_resp = InternalData(auth_info=auth_info)
221222
internal_resp.attributes = self.converter.to_internal("openid", response)
222-
internal_resp.user_id = response["sub"]
223+
internal_resp.subject_id = response["sub"]
223224
return internal_resp
224225

225226
def get_metadata_desc(self):

src/satosa/backends/orcid.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from oic.oauth2.message import AuthorizationResponse
1212

1313
from satosa.backends.oauth import _OAuthBackend
14-
from ..internal_data import InternalResponse
15-
from ..internal_data import AuthenticationInformation
16-
from ..response import Redirect
14+
from satosa.internal import InternalData
15+
from satosa.internal import AuthenticationInformation
16+
from satosa.response import Redirect
1717

1818
logger = logging.getLogger(__name__)
1919

@@ -32,7 +32,7 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
3232
:param base_url: base url of the service
3333
:param name: name of the plugin
3434
:type outgoing:
35-
(satosa.context.Context, satosa.internal_data.InternalResponse) ->
35+
(satosa.context.Context, satosa.internal.InternalData) ->
3636
satosa.response.Response
3737
:type internal_attributes: dict[string, dict[str, str | list[str]]]
3838
:type config: dict[str, dict[str, str] | list[str] | str]
@@ -51,7 +51,7 @@ def start_auth(self, context, internal_request, get_state=stateID):
5151
5252
:type get_state: Callable[[str, bytes], str]
5353
:type context: satosa.context.Context
54-
:type internal_request: satosa.internal_data.InternalRequest
54+
:type internal_request: satosa.internal.InternalData
5555
:rtype satosa.response.Redirect
5656
"""
5757
request_args = dict(
@@ -85,10 +85,10 @@ def _authn_response(self, context):
8585
orcid, name = response['orcid'], response['name']
8686
user_info = self.user_information(token, orcid, name)
8787
auth_info = self.auth_info(context.request)
88-
internal_response = InternalResponse(auth_info=auth_info)
88+
internal_response = InternalData(auth_info=auth_info)
8989
internal_response.attributes = self.converter.to_internal(
9090
self.external_type, user_info)
91-
internal_response.user_id = orcid
91+
internal_response.subject_id = orcid
9292
return self.auth_callback_func(context, internal_response)
9393

9494
def user_information(self, access_token, orcid, name):

0 commit comments

Comments
 (0)