Skip to content

Commit 4cf4920

Browse files
committed
Presentation phase
1 parent 4845639 commit 4cf4920

3 files changed

Lines changed: 61 additions & 56 deletions

File tree

app/routes/wallet_routes.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
sanitize_for_logging,
1818
unescape_json,
1919
unix_ts_to_str_datetime,
20+
parse_url_to_dict,
2021
)
2122
from settings import CONTENT_PDF_BASE_64_PREFIX, ISO_18013_5_NAME, JWT_PREFIX, MSO_MDOC_PREFIX, SD_JWT_PREFIX
2223

@@ -390,10 +391,27 @@ def presentation_phase():
390391
qrcode_data = body["qrcode_data"]
391392
_clear_session() # todo can remove it?
392393
print(f"qrcode_data: {qrcode_data}")
393-
return dict(
394-
result=200,
395-
message="Presentazione avvenuta con successo!"
396-
)
394+
395+
it_wallet_service = ItWalletService(session, external_discovery=True)
396+
try:
397+
params = parse_url_to_dict(qrcode_data)
398+
# @Todo Understand how need requestUriMethod and State ??
399+
it_wallet_service.loginToVerifier(params.get("client_id"),params.get("request_uri"),"", "")
400+
except Exception as e:
401+
logger.error(f"Error, message: {e}")
402+
# @Todo insert this into Util
403+
return jsonify({
404+
"success": False,
405+
"error_message": f"Exception :{e}."
406+
}), 400
407+
408+
session_id = request.args.get("session_id", "")
409+
print(f"session_id: {session_id}")
410+
return jsonify({
411+
"success": True,
412+
"success_message": "Login success."
413+
}), 200
414+
397415

398416
def _create_credential_metadata(credential_key, claims):
399417
logger.info(f"Credential key: {credential_key} claims: {claims}")

app/service/itwallet_service.py

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ def complete_add_credential_wallet(self, credentials_presenting: list[dict]):
941941

942942
return {"success": True, "data": {"credential_id": credential_id}}
943943

944+
# @TODO Update this method to handle the complete flow to login into the wallet and present the credential to the RP
944945
def loginToVerifier(self, clientId: str, requestUri: str, requestUriMethod: str, state: str):
945946
"""
946947
Metodo pubblico per effettuare il login ad un Relying Party / Verifier, incluso fetch dell'EC del Relying Party / Verifier.
@@ -950,32 +951,31 @@ def loginToVerifier(self, clientId: str, requestUri: str, requestUriMethod: str,
950951
self.session["rp_state"]
951952
self.session["rp_response_uri"]
952953
"""
953-
logger.info(
954-
"➡️ Richiesta di login presso il Relying Party / Verifier %s",
955-
sanitize_for_logging(clientId),
956-
)
954+
955+
956+
logger.info(f"Entering method: loginToVerifier. Params [client_id: {clientId}, request_uri: {requestUri}, requestUriMethod: {requestUriMethod}, state: {state}]")
957957

958958
session_id = self.session.get("session_id")
959959
if not session_id:
960960
raise ValueError("Sessione non inizializzata")
961961

962-
# recupero del response_mode relativo al presentation flow dalla configurazione e sua validazione
963-
presentation_response_mode = extract_claim(current_app.config, "metadata.presentation_flow.response_mode")
964-
965-
presentation_response_mode_supported = [PRESENTATION_RESPONSE_MODE_DIRECT_POST_JWT]
966-
if presentation_response_mode not in presentation_response_mode_supported:
967-
raise ValueError(
968-
f"Il response_mode '{presentation_response_mode}' configurato per la presentazione delle credenziali del wallet non è supportato, i valori ammessi sono: {presentation_response_mode_supported}"
969-
)
970-
971-
# recupero del response_type relativo al presentation flow dalla configurazione e sua validazione
972-
presentation_response_type = extract_claim(current_app.config, "metadata.presentation_flow.response_type")
973-
974-
presentation_response_type_supported = [PRESENTATION_RESPONSE_TYPE_VP_TOKEN]
975-
if presentation_response_type not in presentation_response_type_supported:
976-
raise ValueError(
977-
f"Il response_type '{presentation_response_type}' configurato per l'inizializzazione del wallet non è supportato, i valori ammessi sono: {presentation_response_type_supported}"
978-
)
962+
# # recupero del response_mode relativo al presentation flow dalla configurazione e sua validazione
963+
# presentation_response_mode = extract_claim(current_app.config, "metadata.presentation_flow.response_mode")
964+
#
965+
# presentation_response_mode_supported = [PRESENTATION_RESPONSE_MODE_DIRECT_POST_JWT]
966+
# if presentation_response_mode not in presentation_response_mode_supported:
967+
# raise ValueError(
968+
# f"Il response_mode '{presentation_response_mode}' configurato per la presentazione delle credenziali del wallet non è supportato, i valori ammessi sono: {presentation_response_mode_supported}"
969+
# )
970+
#
971+
# # recupero del response_type relativo al presentation flow dalla configurazione e sua validazione
972+
# presentation_response_type = extract_claim(current_app.config, "metadata.presentation_flow.response_type")
973+
#
974+
# presentation_response_type_supported = [PRESENTATION_RESPONSE_TYPE_VP_TOKEN]
975+
# if presentation_response_type not in presentation_response_type_supported:
976+
# raise ValueError(
977+
# f"Il response_type '{presentation_response_type}' configurato per l'inizializzazione del wallet non è supportato, i valori ammessi sono: {presentation_response_type_supported}"
978+
# )
979979

980980
country = app_state.selected_country
981981
query_trust_root = f"ms_trust_configuration.{country}.trust_root"
@@ -984,32 +984,17 @@ def loginToVerifier(self, clientId: str, requestUri: str, requestUriMethod: str,
984984
if not trust_root_url:
985985
raise ValueError(f"Nessun Trust root per il paese {country}")
986986

987-
logger.info(
988-
"ℹ️ Trust root individuato per il paese %s: %s",
989-
sanitize_for_logging(country),
990-
sanitize_for_logging(trust_root_url),
991-
)
992-
993-
# recupero EC del verifier
994-
logger.info(
995-
"➡️ Entity ID del Relying Party / Verifier: %s",
996-
sanitize_for_logging(clientId),
997-
)
987+
logger.info(f"query_trust_root: {query_trust_root}")
998988

999989
# Richiama il metodo privato per ottenere l'EC, validarlo e recuperne il payload
1000990
external_verifier_ec = self._entity_configuration_management(
1001991
clientId, [METADATA_TYPE_FEDERATION_ENTITY, METADATA_TYPE_CREDENTIAL_VERIFIER], trust_root_url
1002992
)
1003993

1004-
logger.info(
1005-
f"✅ Scaricato e validato l'Entity Configuration dell'entità {clientId} di tipo {METADATA_TYPE_CREDENTIAL_VERIFIER}"
1006-
)
994+
logger.info(f"EC for {clientId} validated successfully with metadata types: {[METADATA_TYPE_FEDERATION_ENTITY, METADATA_TYPE_CREDENTIAL_VERIFIER]}")
1007995

1008996
# Salvataggio in memoria Flask external_verifier_ec
1009997
app_state.ec_store.add(clientId, external_verifier_ec)
1010-
logger.info(
1011-
f"✅ Salvato in memoria il payload dell'Entity Configuration dell'entità {clientId} di tipo {METADATA_TYPE_CREDENTIAL_VERIFIER}"
1012-
)
1013998

1014999
# Build authorization query string
10151000
params = {
@@ -1020,20 +1005,13 @@ def loginToVerifier(self, clientId: str, requestUri: str, requestUriMethod: str,
10201005
}
10211006
query_string = f"?{urlencode(params)}"
10221007

1023-
logger.info(
1024-
"🚀 Invio Request_uri request al Request_uri endpoint %s",
1025-
sanitize_for_logging(requestUri),
1026-
)
1027-
# Effettua una request_uri request
1008+
logger.info(f"send request: {requestUri}")
1009+
10281010
request_uri_response = request_request_uri(
10291011
url=requestUri, query_string=query_string, proxies=self.proxies, no_proxy_domains=self.no_proxy_domains
10301012
)
10311013

1032-
logger.info(
1033-
"✅ Ricevuta risposta dal Request_uri endpoint %s",
1034-
sanitize_for_logging(requestUri),
1035-
)
1036-
logger.info("%s", sanitize_for_logging(request_uri_response))
1014+
logger.info(f"response: {request_uri_response}")
10371015

10381016
if not is_jwt(request_uri_response):
10391017
raise ValueError("La Request_uri response ricevuta dal Relying Party / Verifier non è un JWT")
@@ -1044,9 +1022,6 @@ def loginToVerifier(self, clientId: str, requestUri: str, requestUriMethod: str,
10441022
if not verifier_jwks:
10451023
raise ValueError(f"Non trovata in memoria alcuna chiave JWK del Relying Party / Verifier {clientId}")
10461024

1047-
logger.debug("🔑 JWKs trovato:")
1048-
logger.debug("%s", sanitize_for_logging(json.dumps(verifier_jwks, indent=2, ensure_ascii=False)))
1049-
10501025
try:
10511026
request_uri_response_jwt_payload = decode_and_verify_jwt(request_uri_response, verifier_jwks)
10521027
credentialsRequested, rp_state, rp_nonce, rp_response_uri = parse_rp_authorization_request(

app/utils/utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from datetime import datetime, timezone
1010
from typing import Tuple, Union
1111
from urllib.parse import parse_qs, urlparse
12-
1312
import fitz
1413
import jmespath
1514
from cryptography.hazmat.backends import default_backend
@@ -541,3 +540,16 @@ def unescape_json(value):
541540
return [unescape_json(v) for v in value]
542541
else:
543542
return value
543+
544+
545+
546+
def parse_url_to_dict(input : str) -> dict:
547+
logger.info(f"Entering parse_url_string. Params [parse_url_string: {parse_url_string}]")
548+
549+
parsed_url = urlparse(input)
550+
551+
query_dict = {key: value[0] for key, value in parse_qs(parsed_url.query).items()}
552+
553+
logger.info(f"query_dict: {query_dict}")
554+
555+
return query_dict

0 commit comments

Comments
 (0)