From 8145ce57cc82a05be7ef6a7453f7137e84af7c67 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 14 Nov 2024 04:02:40 +0100 Subject: [PATCH] `webfinger`: Parse query string with `serde` and `axum_extra` --- .idea/acrate.iml | 1 + acrate-webfinger/Cargo.toml | 2 ++ acrate-webfinger/src/main.rs | 2 +- acrate-webfinger/src/route.rs | 22 +++++++++++++++------- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.idea/acrate.iml b/.idea/acrate.iml index 983a32b..32d223d 100644 --- a/.idea/acrate.iml +++ b/.idea/acrate.iml @@ -9,6 +9,7 @@ + diff --git a/acrate-webfinger/Cargo.toml b/acrate-webfinger/Cargo.toml index 4640b18..5c74e51 100644 --- a/acrate-webfinger/Cargo.toml +++ b/acrate-webfinger/Cargo.toml @@ -6,7 +6,9 @@ edition = "2021" [dependencies] anyhow = "1.0.93" axum = "0.7.7" +axum-extra = { version = "0.9.4", features = ["query"] } log = "0.4.22" micronfig = "0.3.0" pretty_env_logger = "0.5.0" +serde = { version = "1.0.215", features = ["derive"] } tokio = { version = "1.41.1", features = ["macros", "net", "rt-multi-thread"] } diff --git a/acrate-webfinger/src/main.rs b/acrate-webfinger/src/main.rs index 8958b4c..cc8ad4d 100644 --- a/acrate-webfinger/src/main.rs +++ b/acrate-webfinger/src/main.rs @@ -11,7 +11,7 @@ async fn main() -> anyhow::Result { log::trace!("Creating Axum router..."); let app = axum::Router::new() - .route("/inbox", axum::routing::post(route::inbox_handler)); + .route("/.well-known/webfinger", axum::routing::get(route::webfinger_handler)); log::trace!("Axum router created successfully!"); log::trace!("Creating Tokio listener..."); diff --git a/acrate-webfinger/src/route.rs b/acrate-webfinger/src/route.rs index ca9ec6b..82a7986 100644 --- a/acrate-webfinger/src/route.rs +++ b/acrate-webfinger/src/route.rs @@ -1,8 +1,16 @@ -#[allow(unreachable_code)] -pub async fn inbox_handler() { - todo!("pre-validation hook"); - todo!("validate signature"); - todo!("post-validation hook"); - todo!("database storage"); - todo!("post-storage hook"); +use axum_extra::extract::Query; +use serde::Deserialize; + +#[derive(Debug, Clone, Deserialize)] +pub struct WebfingerQuery { + pub resource: String, + + #[serde(default)] + pub rel: Vec, +} + +pub async fn webfinger_handler( + Query(WebfingerQuery {resource, rel}): Query +) { + todo!() }