From 7f909f889ef634b7ff1c65937a513f0a6c70cd1b Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 14 Aug 2024 15:30:00 +0100 Subject: [PATCH] Add info field to Outcome::Success. This streamlines the implementation, allowing the backend to pass information to the frontend through the receipt of the status. --- src/verifier/session.rs | 5 +++-- tests/e2e.rs | 5 ++++- tests/jwt_vc.rs | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/verifier/session.rs b/src/verifier/session.rs index 0380b95..41fc454 100644 --- a/src/verifier/session.rs +++ b/src/verifier/session.rs @@ -2,6 +2,7 @@ use std::{collections::BTreeMap, fmt::Debug, sync::Arc}; use anyhow::{bail, Error, Ok, Result}; use async_trait::async_trait; +use serde_json::Value as Json; use tokio::sync::Mutex; use uuid::Uuid; @@ -38,7 +39,7 @@ pub enum Outcome { /// The authorization response did not pass verification. Failure { reason: String }, /// The authorization response is verified. - Success, + Success { info: Json }, } /// Storage interface for session information. @@ -111,7 +112,7 @@ impl Outcome { match self { Outcome::Error { .. } => 0, Outcome::Failure { .. } => 1, - Outcome::Success => 2, + Outcome::Success { .. } => 2, } } } diff --git a/tests/e2e.rs b/tests/e2e.rs index a9f8b22..7a6e47a 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -92,5 +92,8 @@ async fn w3c_vc_did_client_direct_post() { assert_eq!(None, redirect); let status = verifier.poll_status(id).await.unwrap(); - assert_eq!(Status::Complete(Outcome::Success), status); + match status { + Status::Complete(Outcome::Success { .. }) => (), + _ => panic!("unexpected status: {status:?}"), + } } diff --git a/tests/jwt_vc.rs b/tests/jwt_vc.rs index 0c218b7..a102c9e 100644 --- a/tests/jwt_vc.rs +++ b/tests/jwt_vc.rs @@ -152,7 +152,13 @@ impl AsyncHttpClient for MockHttpClient { id.parse().context("failed to parse id")?, AuthorizationResponse::from_x_www_form_urlencoded(body) .context("failed to parse authorization response request")?, - |_, _| Box::pin(async { Outcome::Success }), + |_, _| { + Box::pin(async { + Outcome::Success { + info: serde_json::Value::Null, + } + }) + }, ) .await?;