use axum_keycloak_auth::PassthroughMode;
use serde::Deserialize;
#[derive(Clone, Deserialize)]
pub struct KeycloakSettings {
pub url: String,
pub realm: String,
pub expected_audiences: Vec<String>,
pub passthrough_mode: PassthroughModeDef,
pub persist_raw_claims: bool,
}
#[derive(Clone, Deserialize)]
pub struct Settings {
pub keycloak_settings: KeycloakSettings,
}
#[derive(Debug, Clone)]
pub struct PassthroughModeDef(pub PassthroughMode);
impl<'de> Deserialize<'de> for PassthroughModeDef {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
match s.to_lowercase().as_str() {
"block" => Ok(PassthroughModeDef(PassthroughMode::Block)),
"pass" => Ok(PassthroughModeDef(PassthroughMode::Pass)),
_ => Err(serde::de::Error::custom(format!(
"Invalid passthrough mode: {}",
s
))),
}
}
}