From 0c636f3de281a69f190c97114d03950d45738d90 Mon Sep 17 00:00:00 2001 From: peppelinux Date: Fri, 21 Jul 2023 13:25:04 +0200 Subject: [PATCH] chore: refactor endpoint registration and init - changes also in configuration --- example/satosa/disco.html | 2 +- example/satosa/pyeudiw_backend.yaml | 12 ++--- pyeudiw/satosa/backend.py | 70 ++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/example/satosa/disco.html b/example/satosa/disco.html index 4f7be81f..391cf5dd 100644 --- a/example/satosa/disco.html +++ b/example/satosa/disco.html @@ -183,7 +183,7 @@

Benvenuto in Nome Organizzazione Spid Discovery Service

- diff --git a/example/satosa/pyeudiw_backend.yaml b/example/satosa/pyeudiw_backend.yaml index 7493da52..38582e9c 100644 --- a/example/satosa/pyeudiw_backend.yaml +++ b/example/satosa/pyeudiw_backend.yaml @@ -3,14 +3,16 @@ name: OpenID4VP config: #Those are the endpoints listed on eudi wallet backend - pre_request_endpoint: '//show_qrcode' - redirect_endpoint: '//redirect_uri' - request_endpoint: '//request_uri' - entity_configuration_endpoint: '//entity_configuration' + + endpoints: + pre_request: '//pre-request' + redirect: '//redirect_uri' + request: '//request_uri' + entity_configuration: '//entity_configuration' error_url: "https://localhost:9999/error_page.html" - qr_code_settings: + qrcode_settings: size: 100 color: '#2B4375' logo_path: diff --git a/pyeudiw/satosa/backend.py b/pyeudiw/satosa/backend.py index 33f04444..af84d3d2 100644 --- a/pyeudiw/satosa/backend.py +++ b/pyeudiw/satosa/backend.py @@ -19,20 +19,34 @@ class OpenID4VPBackend(BackendModule): """ def __init__(self, auth_callback_func, internal_attributes, config, base_url, name): - super().__init__(auth_callback_func, internal_attributes, base_url, name) - - self.entity_configuration_url = config['entity_configuration_endpoint'] - self.pre_request_url = config['pre_request_endpoint'] - self.redirect_url = config['redirect_endpoint'] - self.request_url = config['request_endpoint'] - self.error_url = config['error_url'] + """ + OpenID4VP backend module. + :param auth_callback_func: Callback should be called by the module after the authorization + in the backend is done. + :param internal_attributes: Mapping dictionary between SATOSA internal attribute names and + the names returned by underlying IdP's/OP's as well as what attributes the calling SP's and + RP's expects namevice. + :param config: Configuration parameters for the module. + :param base_url: base url of the service + :param name: name of the plugin + :type auth_callback_func: + (satosa.context.Context, satosa.internal.InternalData) -> satosa.response.Response + :type internal_attributes: dict[string, dict[str, str | list[str]]] + :type config: dict[str, dict[str, str] | list[str]] + :type base_url: str + :type name: str + """ + super().__init__(auth_callback_func, internal_attributes, base_url, name) self.client_id = config['wallet_relying_party']['client_id'] - self.complete_redirect_url = config['wallet_relying_party']['redirect_uris'][0] - self.complete_request_url = config['wallet_relying_party']['request_uris'][0] + + self.absolute_redirect_url = config['wallet_relying_party']['redirect_uris'][0] + self.absolute_request_url = config['wallet_relying_party']['request_uris'][0] - self.qr_settings = config['qr_code_settings'] + self.qrcode_settings = config['qrcode_settings'] self.config = config + + logger.debug(f"Loaded configuration:\n{json.dumps(config)}") def register_endpoints(self): """ @@ -43,17 +57,30 @@ def register_endpoints(self): :return: A list that can be used to map the request to SATOSA to this endpoint. """ url_map = [] - url_map.append( - (f"^{self.entity_configuration_url.lstrip('/')}$", self.entity_configuration)) - url_map.append( - (f"^{self.pre_request_url.lstrip('/')}$", self.pre_request_endpoint)) - url_map.append( - (f"^{self.redirect_url.lstrip('/')}$", self.redirect_endpoint)) - url_map.append( - (f"^{self.request_url.lstrip('/')}$", self.request_endpoint)) + for k, v in self.config['endpoints'].items(): + url_map.append( + ( + f"^{v.lstrip('/')}$", getattr(self, f"{k}_endpoint") + ) + ) + logger.info(f"[OpenID4VP] Loaded endpoint: '{k}'") return url_map - def entity_configuration(self, context, *args): + def start_auth(self, context, internal_request): + """ + This is the start up function of the backend authorization. + + :type context: satosa.context.Context + :type internal_request: satosa.internal.InternalData + :rtype satosa.response.Response + + :param context: the request context + :param internal_request: Information about the authorization request + :return: response + """ + raise NotImplementedError() + + def entity_configuration_endpoint(self, context, *args): jwk = JWK() data = { @@ -166,7 +193,10 @@ def authn_request(self, context, entity_id): :param entity_id: Target IDP entity id :return: response to the user agent """ - + breakpoint() + pass + + def handle_error( self, message: str,