Skip to content

Commit

Permalink
chore: refactor endpoint registration and init - changes also in conf…
Browse files Browse the repository at this point in the history
…iguration
  • Loading branch information
peppelinux committed Jul 21, 2023
1 parent a190a69 commit 0c636f3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 26 deletions.
2 changes: 1 addition & 1 deletion example/satosa/disco.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ <h4 class="">Benvenuto in Nome Organizzazione Spid Discovery Service</h4>

<div class="col-lg-6 text-center">
<!-- IT-WALLET" * begin * -->
<a href="https://localhost:10000/Saml2/disco?entityID=https://eudi.wallet.gov.it" class="italia-it-button italia-it-button-size-xl button-eidas" eidas-idp-button="#eidas-idp-button-xlarge-post" aria-haspopup="false" aria-expanded="false">
<a href="https://localhost:10000/Saml2/disco?entityID=wallet" class="italia-it-button italia-it-button-size-xl button-eidas" eidas-idp-button="#eidas-idp-button-xlarge-post" aria-haspopup="false" aria-expanded="false">
<span class="italia-it-button-icon"><img src="cie/cie_white.svg" alt="Logo IT-Wallet" /></span>
<span class="italia-it-button-text">Entra con IT-Wallet</span>
</a>
Expand Down
12 changes: 7 additions & 5 deletions example/satosa/pyeudiw_backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ name: OpenID4VP

config:
#Those are the endpoints listed on eudi wallet backend
pre_request_endpoint: '/<name>/show_qrcode'
redirect_endpoint: '/<name>/redirect_uri'
request_endpoint: '/<name>/request_uri'
entity_configuration_endpoint: '/<name>/entity_configuration'

endpoints:
pre_request: '/<name>/pre-request'
redirect: '/<name>/redirect_uri'
request: '/<name>/request_uri'
entity_configuration: '/<name>/entity_configuration'

error_url: "https://localhost:9999/error_page.html"

qr_code_settings:
qrcode_settings:
size: 100
color: '#2B4375'
logo_path:
Expand Down
70 changes: 50 additions & 20 deletions pyeudiw/satosa/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0c636f3

Please sign in to comment.