lmrc_auth/lib.rs
1//! # lmrc-auth
2//!
3//! Authentication framework for LMRC Stack applications.
4//!
5//! This library provides a flexible authentication system with support for:
6//! - Multiple authentication providers (database, LDAP, OAuth, etc.)
7//! - Session management
8//! - Password hashing
9//! - Authentication middleware for Axum
10//! - Ready-to-use HTTP handlers
11//!
12//! ## Features
13//!
14//! - `bcrypt` (default) - Password hashing with bcrypt
15//! - `database` - Database-backed authentication provider with SeaORM
16//!
17//! ## Quick Start
18//!
19//! ```rust,ignore
20//! use lmrc_auth::{AuthProvider, DatabaseAuthProvider, AuthConfig};
21//! use sea_orm::Database;
22//! use std::sync::Arc;
23//!
24//! #[tokio::main]
25//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
26//! let db = Database::connect("postgres://localhost/mydb").await?;
27//!
28//! let auth_provider = Arc::new(
29//! DatabaseAuthProvider::new(
30//! db,
31//! "users",
32//! "sessions",
33//! AuthConfig::default()
34//! )
35//! );
36//!
37//! // Use in your Axum application
38//! Ok(())
39//! }
40//! ```
41
42pub mod error;
43pub mod models;
44pub mod traits;
45
46#[cfg(feature = "database")]
47pub mod providers;
48
49pub mod handlers;
50pub mod middleware;
51
52// Re-export commonly used types
53pub use error::{AuthError, AuthResult};
54pub use models::{AuthUser, Credentials, LoginResponse, Session};
55pub use traits::{AuthProvider, SessionStore};
56
57#[cfg(feature = "database")]
58pub use providers::DatabaseAuthProvider;
59
60/// Authentication configuration
61#[derive(Debug, Clone)]
62pub struct AuthConfig {
63 /// Session expiration in hours
64 pub session_expiration_hours: i64,
65 /// Cookie name for session token
66 pub cookie_name: String,
67 /// Cookie domain (optional)
68 pub cookie_domain: Option<String>,
69 /// Cookie secure flag (use HTTPS only)
70 pub cookie_secure: bool,
71}
72
73impl Default for AuthConfig {
74 fn default() -> Self {
75 Self {
76 session_expiration_hours: 168, // 7 days
77 cookie_name: "session_token".to_string(),
78 cookie_domain: None,
79 cookie_secure: true,
80 }
81 }
82}