use warp::{ Filter, Reply, filters::BoxedFilter, http::Uri, }; use crate::app::web::{ CustomRejection, template::index::IndexTemplate, }; use std::collections::HashMap; pub fn access_token_routes() -> BoxedFilter<(impl Reply, )> { warp::get().and(access_token_page()) .or(warp::post().and(access_token_submit())) .boxed() } fn access_token_page() -> BoxedFilter<(impl Reply, )> { warp::path::end() .map(|| IndexTemplate) .boxed() } fn access_token_submit() -> BoxedFilter<(impl Reply, )> { warp::path::end() .and(warp::body::content_length_limit(1024)) .and(warp::body::form()) .and_then(|form: HashMap| async move { let token = match form.get("access_token") { Some(token) => token, None => return Err(warp::reject::custom(CustomRejection::InvalidForm)), }; Ok(warp::reply::with_header( warp::redirect(Uri::from_static("/")), "Set-Cookie", format!("access_token={}; SameSite=Lax; Secure; HttpOnly", token), )) }) .boxed() }