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

BC Wallet deep link display #421

Merged
merged 7 commits into from
Mar 4, 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
3 changes: 2 additions & 1 deletion oidc-controller/api/authSessions/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta
from enum import StrEnum, auto
from typing import Dict
from typing import Dict, Optional

from api.core.acapy.client import AcapyClient
from api.core.models import UUIDModel
Expand All @@ -25,6 +25,7 @@ class AuthSessionBase(BaseModel):
request_parameters: dict
pyop_auth_code: str
response_url: str
presentation_request_msg: Optional[dict] = None

class Config:
allow_population_by_field_name = True
Expand Down
74 changes: 71 additions & 3 deletions oidc-controller/api/routers/oidc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import io
import json
from typing import cast
import uuid
from datetime import datetime
Expand All @@ -18,6 +19,14 @@
from ..authSessions.crud import AuthSessionCreate, AuthSessionCRUD
from ..authSessions.models import AuthSessionPatch, AuthSessionState
from ..core.acapy.client import AcapyClient
from ..core.aries import (
OOBServiceDecorator,
OutOfBandMessage,
OutOfBandPresentProofAttachment,
PresentationRequestMessage,
PresentProofv10Attachment,
ServiceDecorator,
)
from ..core.config import settings
from ..core.logger_util import log_debug
from ..core.oidc import provider
Expand Down Expand Up @@ -105,19 +114,71 @@ async def get_authorize(request: Request, db: Database = Depends(get_db)):

# Create presentation_request to show on screen
response = client.create_presentation_request(ver_config.generate_proof_request())
pres_exch_dict = response.dict()

# Prepeare the presentation request
client = AcapyClient()
use_public_did = (
not settings.USE_OOB_PRESENT_PROOF
) and settings.USE_OOB_LOCAL_DID_SERVICE
wallet_did = client.get_wallet_did(public=use_public_did)

byo_attachment = PresentProofv10Attachment.build(
pres_exch_dict["presentation_request"]
)

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:
wallet_did = client.get_wallet_did(public=True)
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],
)
msg_contents = oob_msg
else:
s_d = ServiceDecorator(
service_endpoint=client.service_endpoint, recipient_keys=[wallet_did.verkey]
)
msg = PresentationRequestMessage(
id=pres_exch_dict["thread_id"],
request=[byo_attachment],
service=s_d,
)
msg_contents = msg


# Create and save OIDC AuthSession
new_auth_session = AuthSessionCreate(
response_url=authn_response.request(auth_req["redirect_uri"]),
pyop_auth_code=authn_response["code"],
request_parameters=model.to_dict(),
ver_config_id=ver_config_id,
pres_exch_id=response.presentation_exchange_id,
presentation_exchange=response.dict(),
presentation_exchange=pres_exch_dict,
presentation_request_msg=msg_contents.dict(by_alias=True),
)

# save OIDC AuthSession
auth_session = await AuthSessionCRUD(db).create(new_auth_session)

formated_msg = json.dumps(msg_contents.dict(by_alias=True))

# QR CONTENTS
controller_host = settings.CONTROLLER_URL
url_to_message = (
Expand All @@ -129,6 +190,12 @@ async def get_authorize(request: Request, db: Database = Depends(get_db)):
image_contents = base64.b64encode(buff.getvalue()).decode("utf-8")
callback_url = f"""{controller_host}{AuthorizeCallbackUri}?pid={auth_session.id}"""

# BC Wallet deep link
# base64 encode the formated_msg
base64_msg = base64.b64encode(formated_msg.encode("utf-8")).decode("utf-8")
wallet_deep_link = f"bcwallet://aries_proof-request?c_i={base64_msg}"


# This is the payload to send to the template
data = {
"image_contents": image_contents,
Expand All @@ -139,6 +206,7 @@ async def get_authorize(request: Request, db: Database = Depends(get_db)):
"pid": auth_session.id,
"controller_host": controller_host,
"challenge_poll_uri": ChallengePollUri,
"wallet_deep_link": wallet_deep_link,
}

# Prepare the template
Expand Down
60 changes: 4 additions & 56 deletions oidc-controller/api/routers/presentation_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@

from ..authSessions.crud import AuthSessionCRUD
from ..authSessions.models import AuthSession, AuthSessionState
from ..core.acapy.client import AcapyClient
from ..core.aries import (
OOBServiceDecorator,
OutOfBandMessage,
OutOfBandPresentProofAttachment,
PresentationRequestMessage,
PresentProofv10Attachment,
ServiceDecorator,
)

from ..core.config import settings
from ..routers.socketio import (sio, connections_reload)
from ..db.session import get_db
Expand Down Expand Up @@ -65,51 +57,7 @@ async def send_connectionless_proof_req(
await AuthSessionCRUD(db).patch(auth_session.id, auth_session)
await sio.emit('status', {'status': 'pending'}, to=sid)

client = AcapyClient()
use_public_did = (
not settings.USE_OOB_PRESENT_PROOF
) and settings.USE_OOB_LOCAL_DID_SERVICE
wallet_did = client.get_wallet_did(public=use_public_did)

byo_attachment = PresentProofv10Attachment.build(
auth_session.presentation_exchange["presentation_request"]
)
msg = auth_session.presentation_request_msg

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:
wallet_did = client.get_wallet_did(public=True)
oob_s_d = wallet_did.verkey

msg = PresentationRequestMessage(
id=auth_session.presentation_exchange["thread_id"],
request=[byo_attachment],
)
oob_msg = OutOfBandMessage(
request_attachments=[
OutOfBandPresentProofAttachment(
id="request-0",
data={"json": msg.dict(by_alias=True)},
)
],
id=auth_session.presentation_exchange["thread_id"],
services=[oob_s_d],
)
msg_contents = oob_msg
else:
s_d = ServiceDecorator(
service_endpoint=client.service_endpoint, recipient_keys=[wallet_did.verkey]
)
msg = PresentationRequestMessage(
id=auth_session.presentation_exchange["thread_id"],
request=[byo_attachment],
service=s_d,
)
msg_contents = msg
logger.debug(msg_contents.dict(by_alias=True))
return JSONResponse(msg_contents.dict(by_alias=True))
logger.debug(msg)
return JSONResponse(msg)
Loading