diff --git a/oidc-controller/api/core/acapy/client.py b/oidc-controller/api/core/acapy/client.py index b0fadf69..fce090ae 100644 --- a/oidc-controller/api/core/acapy/client.py +++ b/oidc-controller/api/core/acapy/client.py @@ -7,7 +7,7 @@ from ..config import settings from .config import AgentConfig, MultiTenantAcapy, SingleTenantAcapy -from .models import CreatePresentationResponse, WalletDid +from .models import CreatePresentationResponse, OobCreateInvitationResponse, WalletDid _client = None logger = structlog.getLogger(__name__) @@ -16,6 +16,7 @@ PUBLIC_WALLET_DID_URI = "/wallet/did/public" CREATE_PRESENTATION_REQUEST_URL = "/present-proof/create-request" PRESENT_PROOF_RECORDS = "/present-proof/records" +OOB_CREATE_INVITATION = "/out-of-band/create-invitation" class AcapyClient: @@ -125,3 +126,33 @@ def get_wallet_did(self, public=False) -> WalletDid: logger.debug(f"<<< get_wallet_did -> {did}") return did + + def oob_create_invitation( + self, presentation_exchange: dict, use_public_did: bool + ) -> OobCreateInvitationResponse: + logger.debug(">>> oob_create_invitation") + create_invitation_payload = { + "attachments": [ + { + "id": presentation_exchange["presentation_exchange_id"], + "type": "present-proof", + "data": {"json": presentation_exchange}, + } + ], + "use_public_did": use_public_did, + } + + resp_raw = requests.post( + self.acapy_host + OOB_CREATE_INVITATION, + headers=self.agent_config.get_headers(), + json=create_invitation_payload, + ) + + # TODO: Determine if this should assert it received a json object + assert resp_raw.status_code == 200, resp_raw.content + + resp = json.loads(resp_raw.content) + result = OobCreateInvitationResponse.parse_obj(resp) + + logger.debug("<<< oob_create_invitation") + return result diff --git a/oidc-controller/api/core/acapy/models.py b/oidc-controller/api/core/acapy/models.py index 7b4df94c..8aa9a62e 100644 --- a/oidc-controller/api/core/acapy/models.py +++ b/oidc-controller/api/core/acapy/models.py @@ -1,4 +1,5 @@ from typing import Optional, Dict +from ..aries import OutOfBandMessage from pydantic import BaseModel @@ -17,3 +18,12 @@ class CreatePresentationResponse(BaseModel): thread_id: str presentation_exchange_id: str presentation_request: Dict + + +class OobCreateInvitationResponse(BaseModel): + invi_msg_id: str + invitation_url: str + oob_id: str + trace: bool + state: str + invitation: OutOfBandMessage diff --git a/oidc-controller/api/core/aries/service_decorator.py b/oidc-controller/api/core/aries/service_decorator.py index 937edc18..a6041303 100644 --- a/oidc-controller/api/core/aries/service_decorator.py +++ b/oidc-controller/api/core/aries/service_decorator.py @@ -13,9 +13,9 @@ class ServiceDecorator(BaseModel): class OOBServiceDecorator(ServiceDecorator): # ServiceDecorator - recipient_keys: Optional[List[str]] = None - routing_keys: Optional[List[str]] = Field(default=[]) - service_endpoint: Optional[str] = None + recipient_keys: Optional[List[str]] = Field(default=None, alias="recipientKeys") + routing_keys: Optional[List[str]] = Field(default=None, alias="routingKeys") + service_endpoint: Optional[str] = Field(default=None, alias="serviceEndpoint") id: str = Field(default="did:vc-authn-oidc:123456789zyxwvutsr#did-communication") type: str = Field(default="did-communication") priority: int = 0 diff --git a/oidc-controller/api/routers/oidc.py b/oidc-controller/api/routers/oidc.py index 62240308..ded9e567 100644 --- a/oidc-controller/api/routers/oidc.py +++ b/oidc-controller/api/routers/oidc.py @@ -20,9 +20,6 @@ from ..authSessions.models import AuthSessionPatch, AuthSessionState from ..core.acapy.client import AcapyClient from ..core.aries import ( - OOBServiceDecorator, - OutOfBandMessage, - OutOfBandPresentProofAttachment, PresentationRequestMessage, PresentProofv10Attachment, ServiceDecorator, @@ -124,29 +121,10 @@ async def get_authorize(request: Request, db: Database = Depends(get_db)): msg = None if settings.USE_OOB_PRESENT_PROOF: - if settings.USE_OOB_LOCAL_DID_SERVICE: - oob_s_d = OOBServiceDecorator( - service_endpoint=client.service_endpoint, - recipient_keys=[wallet_did.verkey], - ).dict() - else: - oob_s_d = wallet_did.verkey - - msg = PresentationRequestMessage( - id=pres_exch_dict["thread_id"], - request=[byo_attachment], - ) - oob_msg = OutOfBandMessage( - request_attachments=[ - OutOfBandPresentProofAttachment( - id="request-0", - data={"json": msg.dict(by_alias=True)}, - ) - ], - id=pres_exch_dict["thread_id"], - services=[oob_s_d], + oob_invite_response = client.oob_create_invitation( + pres_exch_dict, use_public_did ) - msg_contents = oob_msg + msg_contents = oob_invite_response.invitation else: s_d = ServiceDecorator( service_endpoint=client.service_endpoint, recipient_keys=[wallet_did.verkey]