Phase 1: Fix compilation (config_path Option<PathBuf>, streaming test, stale test cleanup) Phase 2: Fix critical bugs (remove block_on deadlocks in 4 providers, fix broken SQL query builder) Phase 3: Security hardening (session manager, real auth, token masking, Gemini key to header, password policy) Phase 4: Implement stubs (real provider test, /proc health metrics, client/provider/backup endpoints, has_images) Phase 5: Code quality (shared provider helpers, explicit re-exports, all Clippy warnings fixed, unwrap removal, 6 unused deps removed, dashboard split into 7 sub-modules) Phase 6: Infrastructure (GitHub Actions CI, multi-stage Dockerfile, rustfmt.toml, clippy.toml, script fixes)
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
use axum::{extract::FromRequestParts, http::request::Parts};
|
|
use axum_extra::TypedHeader;
|
|
use axum_extra::headers::Authorization;
|
|
use headers::authorization::Bearer;
|
|
|
|
use crate::errors::AppError;
|
|
|
|
pub struct AuthenticatedClient {
|
|
pub token: String,
|
|
pub client_id: String,
|
|
}
|
|
|
|
impl<S> FromRequestParts<S> for AuthenticatedClient
|
|
where
|
|
S: Send + Sync,
|
|
{
|
|
type Rejection = AppError;
|
|
|
|
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
|
// Extract bearer token from Authorization header
|
|
let TypedHeader(Authorization(bearer)) = TypedHeader::<Authorization<Bearer>>::from_request_parts(parts, state)
|
|
.await
|
|
.map_err(|_| AppError::AuthError("Missing or invalid bearer token".to_string()))?;
|
|
|
|
let token = bearer.token().to_string();
|
|
|
|
// Derive client_id from the token prefix
|
|
let client_id = format!("client_{}", &token[..8.min(token.len())]);
|
|
|
|
Ok(AuthenticatedClient { token, client_id })
|
|
}
|
|
}
|
|
|
|
pub fn validate_token(token: &str, valid_tokens: &[String]) -> bool {
|
|
// Simple validation against list of tokens
|
|
// In production, use proper token validation (JWT, database lookup, etc.)
|
|
valid_tokens.contains(&token.to_string())
|
|
}
|