nom-nom-nix-gc/src/filters/mod.rs

43 lines
1.7 KiB
Rust
Raw Normal View History

2023-02-06 20:26:05 +01:00
use serde::de::DeserializeOwned;
2022-12-22 13:50:53 +01:00
use warp::Filter;
2023-02-06 20:26:05 +01:00
use webauthn_rs::prelude::RegisterPublicKeyCredential;
2022-12-22 13:50:53 +01:00
use crate::handlers;
2023-01-08 17:59:58 +01:00
use crate::models;
2022-12-22 13:50:53 +01:00
2023-01-08 17:59:58 +01:00
2023-02-06 20:26:05 +01:00
pub fn all(state: models::AppState) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone + '_{
2023-01-08 17:59:58 +01:00
landing(state.clone())
.or(start_webauthn_registration(state.clone()))
2023-02-06 20:26:05 +01:00
.or(finish_webauthn_registration(state.clone()))
2023-01-08 17:59:58 +01:00
}
2023-02-06 20:26:05 +01:00
pub fn landing(state: models::AppState) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone + '_ {
2023-01-08 17:59:58 +01:00
warp::path::end()
.and(warp::any().map(move || state.clone()))
.and_then(handlers::landing_page)
}
2023-02-06 20:26:05 +01:00
pub fn start_webauthn_registration<'a>(state: models::AppState<'a>) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone + 'a {
2023-01-22 18:12:45 +01:00
warp::path!("account" / "register-init")
2022-12-22 13:50:53 +01:00
.and(warp::post())
2023-02-06 20:26:05 +01:00
.and(json_body::<models::User>())
2023-01-08 17:59:58 +01:00
.and(warp::any().map(move || state.clone()))
2022-12-22 13:50:53 +01:00
.and_then(handlers::start_webauthn_registration)
}
2023-02-06 20:26:05 +01:00
pub fn finish_webauthn_registration<'a>(state: models::AppState<'a>) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone + 'a {
warp::path!("account" / "register-finish")
.and(warp::post())
.and(json_body::<RegisterPublicKeyCredential>())
.and(warp::any().map(move || state.clone()))
.and(warp::cookie("uuid"))
.and_then(handlers::finish_webauthn_registration)
}
fn json_body<'a, M: Send + DeserializeOwned>() -> impl Filter<Extract = (M,), Error = warp::Rejection> + Clone {
2022-12-22 13:50:53 +01:00
// When accepting a body, we want a JSON body
// (and to reject huge payloads)...
warp::body::content_length_limit(1024 * 16).and(warp::body::json())
}