use serde::{Deserialize, Serialize};
use tower_http::validate_request::ValidateRequestHeaderLayer;
use super::ApplyLayer;
use crate::automatic_body::add_automatic_body;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct RequireBasicAuthConfig {
username: String,
password: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct RequireBearerAuthConfig {
token: String,
}
pub fn basic_from_config(config: RequireBasicAuthConfig) -> anyhow::Result<impl ApplyLayer> {
Ok(add_automatic_body(ValidateRequestHeaderLayer::basic(
&config.username,
&config.password,
)))
}
pub fn bearer_from_config(config: RequireBearerAuthConfig) -> anyhow::Result<impl ApplyLayer> {
Ok(add_automatic_body(ValidateRequestHeaderLayer::bearer(
&config.token,
)))
}