lmrc-auth 0.3.13

Authentication framework for LMRC Stack applications
Documentation
//! Authentication middleware for Axum

use axum::{
    extract::{Request, State},
    http::StatusCode,
    middleware::Next,
    response::Response,
};
use std::sync::Arc;

use crate::{traits::AuthProvider, AuthConfig};

/// Authentication middleware
///
/// Validates session token from cookie or Authorization header.
///
/// ## Example
///
/// ```rust,ignore
/// use axum::{Router, middleware};
/// use lmrc_auth::middleware::auth_middleware;
///
/// let protected = Router::new()
///     .route("/protected", get(handler))
///     .layer(middleware::from_fn_with_state(
///         (auth_provider, config),
///         auth_middleware::<MyAuthProvider>
///     ));
/// ```
pub async fn auth_middleware<P>(
    State((_provider, _config)): State<(Arc<P>, AuthConfig)>,
    request: Request,
    next: Next,
) -> Result<Response, StatusCode>
where
    P: AuthProvider,
{
    // TODO: Extract token from cookie or Authorization header
    // TODO: Validate session
    // TODO: Inject user info into request extensions

    // For now, just pass through
    Ok(next.run(request).await)
}