Handle non-authentication actions

This commit is contained in:
puck 2025-12-08 11:55:00 +00:00
parent 8f188a05cf
commit 8b812da751
3 changed files with 21 additions and 8 deletions

View file

@ -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<ClientContext> {
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::<HashMap<String, String>>()
.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 {

View file

@ -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 => {

View file

@ -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
};