43 lines
1.7 KiB
Rust
43 lines
1.7 KiB
Rust
use serde::de::DeserializeOwned;
|
|
use warp::Filter;
|
|
use webauthn_rs::prelude::RegisterPublicKeyCredential;
|
|
|
|
use crate::handlers;
|
|
use crate::models;
|
|
|
|
|
|
pub fn all(state: models::AppState) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone + '_{
|
|
landing(state.clone())
|
|
.or(start_webauthn_registration(state.clone()))
|
|
.or(finish_webauthn_registration(state.clone()))
|
|
}
|
|
|
|
pub fn landing(state: models::AppState) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone + '_ {
|
|
warp::path::end()
|
|
.and(warp::any().map(move || state.clone()))
|
|
.and_then(handlers::landing_page)
|
|
}
|
|
|
|
pub fn start_webauthn_registration<'a>(state: models::AppState<'a>) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone + 'a {
|
|
warp::path!("account" / "register-init")
|
|
.and(warp::post())
|
|
.and(json_body::<models::User>())
|
|
.and(warp::any().map(move || state.clone()))
|
|
.and_then(handlers::start_webauthn_registration)
|
|
}
|
|
|
|
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 {
|
|
// 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())
|
|
}
|