use crate::error::GatewayError;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthContext {
pub user_id: String,
pub role: String,
pub claims: std::collections::HashMap<String, serde_json::Value>,
}
impl AuthContext {
pub fn anonymous() -> Self {
Self {
user_id: "anonymous".to_string(),
role: "anonymous".to_string(),
claims: std::collections::HashMap::new(),
}
}
pub fn has_role(&self, role: &str) -> bool {
self.role == role
}
}
pub fn validate_token(_token: &str) -> Result<AuthContext, GatewayError> {
tracing::warn!("JWT validation not implemented, returning anonymous");
Ok(AuthContext::anonymous())
}
pub fn extract_auth_header(headers: &[(String, String)]) -> Option<String> {
headers
.iter()
.find(|(k, _)| k.to_lowercase() == "authorization")
.and_then(|(_, v)| v.strip_prefix("Bearer ").map(String::from))
}