Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Out-Of-Band invitation option for QR codes #556

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion oidc-controller/api/core/acapy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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:
Expand Down Expand Up @@ -125,3 +126,32 @@ 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,
)

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
10 changes: 10 additions & 0 deletions oidc-controller/api/core/acapy/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional, Dict
from ..aries import OutOfBandMessage

from pydantic import BaseModel

Expand All @@ -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
6 changes: 3 additions & 3 deletions oidc-controller/api/core/aries/service_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 3 additions & 25 deletions oidc-controller/api/routers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down