Skip to content

Commit

Permalink
Merge pull request #571 from bcgov/bugfix/noBroadcastingProofWebhooks
Browse files Browse the repository at this point in the history
Don't broadcast socket if no sid found
  • Loading branch information
loneil authored Jul 4, 2024
2 parents 0528f7d + 37e7928 commit a3eed04
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions oidc-controller/api/routers/acapy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async def post_topic(request: Request, topic: str, db: Database = Depends(get_db
pid = str(auth_session.id)
connections = connections_reload()
sid = connections.get(pid)
logger.debug(f"sid: {sid} found for pid: {pid}")

if webhook_body["state"] == "presentation_received":
logger.info("GOT A PRESENTATION, TIME TO VERIFY")
Expand All @@ -53,10 +54,12 @@ async def post_topic(request: Request, topic: str, db: Database = Depends(get_db
logger.info("VERIFIED")
if webhook_body["verified"] == "true":
auth_session.proof_status = AuthSessionState.VERIFIED
await sio.emit("status", {"status": "verified"}, to=sid)
if sid:
await sio.emit("status", {"status": "verified"}, to=sid)
else:
auth_session.proof_status = AuthSessionState.FAILED
await sio.emit("status", {"status": "failed"}, to=sid)
if sid:
await sio.emit("status", {"status": "failed"}, to=sid)

await AuthSessionCRUD(db).patch(
str(auth_session.id), AuthSessionPatch(**auth_session.dict())
Expand All @@ -67,7 +70,9 @@ async def post_topic(request: Request, topic: str, db: Database = Depends(get_db
logger.info("ABANDONED")
logger.info(webhook_body["error_msg"])
auth_session.proof_status = AuthSessionState.ABANDONED
await sio.emit("status", {"status": "abandoned"}, to=sid)
if sid:
await sio.emit("status", {"status": "abandoned"}, to=sid)

await AuthSessionCRUD(db).patch(
str(auth_session.id), AuthSessionPatch(**auth_session.dict())
)
Expand All @@ -91,7 +96,9 @@ async def post_topic(request: Request, topic: str, db: Database = Depends(get_db
):
logger.info("EXPIRED")
auth_session.proof_status = AuthSessionState.EXPIRED
await sio.emit("status", {"status": "expired"}, to=sid)
if sid:
await sio.emit("status", {"status": "expired"}, to=sid)

await AuthSessionCRUD(db).patch(
str(auth_session.id), AuthSessionPatch(**auth_session.dict())
)
Expand Down
3 changes: 2 additions & 1 deletion oidc-controller/api/routers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ async def poll_pres_exch_complete(pid: str, db: Database = Depends(get_db)):
str(auth_session.id), AuthSessionPatch(**auth_session.dict())
)
# Send message through the websocket.
await sio.emit("status", {"status": "expired"}, to=sid)
if sid:
await sio.emit("status", {"status": "expired"}, to=sid)

return {"proof_status": auth_session.proof_status}

Expand Down
3 changes: 2 additions & 1 deletion oidc-controller/api/routers/presentation_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ async def send_connectionless_proof_req(
if auth_session.proof_status is AuthSessionState.NOT_STARTED:
auth_session.proof_status = AuthSessionState.PENDING
await AuthSessionCRUD(db).patch(auth_session.id, auth_session)
await sio.emit("status", {"status": "pending"}, to=sid)
if sid:
await sio.emit("status", {"status": "pending"}, to=sid)

msg = auth_session.presentation_request_msg

Expand Down

0 comments on commit a3eed04

Please sign in to comment.