Parse URL query better

This commit is contained in:
puck 2025-12-08 12:37:27 +00:00
parent 8b812da751
commit c9f0243956
2 changed files with 16 additions and 14 deletions

View file

@ -64,10 +64,18 @@ pub struct PolyDataResponse {
pub result: String,
}
pub async fn wid_init(session_id: &str) -> Option<ClientContext> {
pub async fn wid_init(host: &str, session_id: &str) -> Option<ClientContext> {
let app_host = if host == "digid.nl" {
String::from("app.digid.nl")
} else {
String::from("app-") + host
};
println!("host: {:?}", app_host);
let client = reqwest::Client::new();
let init_req = client
.post("https://app.digid.nl/apps/wid/new")
.post(format!("https://{}/apps/wid/new", app_host))
.json(&serde_json::json!({"app_session_id": session_id.to_owned() }))
.header("API-Version", "3")
.header("App-Version", "6.16.3")
@ -87,7 +95,7 @@ pub async fn wid_init(session_id: &str) -> Option<ClientContext> {
}
client
.post("https://app.digid.nl/apps/wid/confirm")
.post(format!("https://{}/apps/wid/confirm", app_host))
.json(&serde_json::json!({"app_session_id": session_id.to_owned() }))
.header("API-Version", "3")
.header("App-Version", "6.16.3")

View file

@ -1,4 +1,4 @@
use std::{env::args, thread, time::Duration};
use std::{collections::HashMap, env::args, thread, time::Duration};
use der::{Any, Decode, asn1::SetOfVec, oid::ObjectIdentifier};
use openssl::{bn::BigNumContext, ec::PointConversionForm, pkey::PKey};
@ -94,6 +94,7 @@ pub trait Card {
}
async fn run_auth(
host: String,
session_id: String,
ctg_pipe: async_channel::Sender<crate::pipe::CardToGUI>,
gtc_pipe: async_channel::Receiver<crate::pipe::GUIToCard>,
@ -105,7 +106,7 @@ async fn run_auth(
service: String::from("UI Test"),
}
} else {
let Some(ctx) = digid_api::wid_init(&session_id).await else {
let Some(ctx) = digid_api::wid_init(&host, &session_id).await else {
ctg_pipe.send(pipe::CardToGUI::ProcessingMessage { message: "Failed to initialize DigiD session.".to_owned() }).await;
return Ok(());
};
@ -497,17 +498,10 @@ fn main() {
let (gtc_pipe_s, gtc_pipe_r) = async_channel::unbounded();
let s = args().nth(1).unwrap();
let session_id = s
.split('&')
.next()
.unwrap()
.split('=')
.last()
.unwrap()
.to_owned();
let mut parsed_url = url::form_urlencoded::parse(s.split(':').last().unwrap().as_bytes()).into_owned().collect::<HashMap<String, String>>();
let rt = Runtime::new().unwrap();
rt.spawn(async { run_auth(session_id, ctg_pipe_s, gtc_pipe_r).await.unwrap() });
rt.spawn(async move { run_auth(parsed_url.remove("host").unwrap_or_else(|| String::from("test")), parsed_url.remove("app_session_id").unwrap_or_else(|| String::from("test")), ctg_pipe_s, gtc_pipe_r).await.unwrap() });
gui::run_gui(ctg_pipe_r, gtc_pipe_s);
}