From 8b812da751fa60622d7085dd491f7b344184c126 Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Mon, 8 Dec 2025 11:55:00 +0000 Subject: [PATCH] Handle non-authentication actions --- src/digid_api.rs | 21 +++++++++++++++------ src/gui.rs | 2 +- src/main.rs | 6 +++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/digid_api.rs b/src/digid_api.rs index 785dded..824dbd1 100644 --- a/src/digid_api.rs +++ b/src/digid_api.rs @@ -64,7 +64,7 @@ pub struct PolyDataResponse { pub result: String, } -pub async fn wid_init(session_id: &str) -> ClientContext { +pub async fn wid_init(session_id: &str) -> Option { let client = reqwest::Client::new(); let init_req = client .post("https://app.digid.nl/apps/wid/new") @@ -82,9 +82,10 @@ pub async fn wid_init(session_id: &str) -> ClientContext { .await .unwrap(); - println!("{:?}", init_req); + if init_req.get("status").map(|f| f == "OK") != Some(true) { + return None; + } - let wid_session_id = init_req.get("session_id").unwrap().to_owned(); client .post("https://app.digid.nl/apps/wid/confirm") .json(&serde_json::json!({"app_session_id": session_id.to_owned() })) @@ -100,11 +101,19 @@ pub async fn wid_init(session_id: &str) -> ClientContext { .json::>() .await .unwrap(); - ClientContext { + + let wid_session_id = init_req.get("session_id").unwrap().to_owned(); + Some(ClientContext { host: init_req.get("url").unwrap().to_owned(), session: wid_session_id, - service: init_req.get("webservice").unwrap().to_owned(), - } + service: if let Some(v) = init_req.get("webservice") { + format!("log in to {}", v) + } else if let Some(v) = init_req.get("action") { + format!("perform '{}'", v) + } else { + "unknown action".to_owned() + }, + }) } pub struct ClientContext { diff --git a/src/gui.rs b/src/gui.rs index 36f9d30..06a3a6b 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -127,7 +127,7 @@ fn build_ui( while let Ok(msg) = ctg_pipe.recv().await { match msg { pipe::CardToGUI::AuthenticationTarget { target } => { - info_label.set_text(&format!("Enter your PIN to log in to {}", target)); + info_label.set_text(&format!("Enter your PIN to {}", target)); } pipe::CardToGUI::WaitForCard => { diff --git a/src/main.rs b/src/main.rs index 6a2a4a7..39d2287 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,7 +105,11 @@ async fn run_auth( service: String::from("UI Test"), } } else { - let ctx = digid_api::wid_init(&session_id).await; + let Some(ctx) = digid_api::wid_init(&session_id).await else { + ctg_pipe.send(pipe::CardToGUI::ProcessingMessage { message: "Failed to initialize DigiD session.".to_owned() }).await; + return Ok(()); + }; + ctx.start().await; ctx };