Handle non-authentication actions
This commit is contained in:
parent
2662917b29
commit
f53f76b748
|
|
@ -64,7 +64,7 @@ pub struct PolyDataResponse {
|
||||||
pub result: String,
|
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 client = reqwest::Client::new();
|
||||||
let init_req = client
|
let init_req = client
|
||||||
.post("https://app.digid.nl/apps/wid/new")
|
.post("https://app.digid.nl/apps/wid/new")
|
||||||
|
|
@ -82,9 +82,10 @@ pub async fn wid_init(session_id: &str) -> ClientContext {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.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
|
client
|
||||||
.post("https://app.digid.nl/apps/wid/confirm")
|
.post("https://app.digid.nl/apps/wid/confirm")
|
||||||
.json(&serde_json::json!({"app_session_id": session_id.to_owned() }))
|
.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>>()
|
.json::<HashMap<String, String>>()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
ClientContext {
|
|
||||||
|
let wid_session_id = init_req.get("session_id").unwrap().to_owned();
|
||||||
|
Some(ClientContext {
|
||||||
host: init_req.get("url").unwrap().to_owned(),
|
host: init_req.get("url").unwrap().to_owned(),
|
||||||
session: wid_session_id,
|
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 {
|
pub struct ClientContext {
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ fn build_ui(
|
||||||
while let Ok(msg) = ctg_pipe.recv().await {
|
while let Ok(msg) = ctg_pipe.recv().await {
|
||||||
match msg {
|
match msg {
|
||||||
pipe::CardToGUI::AuthenticationTarget { target } => {
|
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 => {
|
pipe::CardToGUI::WaitForCard => {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,11 @@ async fn run_auth(
|
||||||
service: String::from("UI Test"),
|
service: String::from("UI Test"),
|
||||||
}
|
}
|
||||||
} else {
|
} 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.start().await;
|
||||||
ctx
|
ctx
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue