oxify_authn/
lib.rs

1//! # `OxiFY` Authentication Module
2//!
3//! Ported from `OxiRS` (<https://github.com/cool-japan/oxirs>)
4//! Original implementation: Copyright (c) `OxiRS` Contributors
5//! Adapted for `OxiFY`
6//! License: MIT OR Apache-2.0 (compatible with `OxiRS`)
7//!
8//! This crate provides enterprise-grade authentication for `OxiFY`, including:
9//! - JWT token management
10//! - OAuth2/OIDC integration
11//! - SAML authentication
12//! - LDAP/Active Directory
13//! - Password hashing and validation
14//! - Multi-factor authentication (MFA)
15//!
16//! ## Example
17//!
18//! ```no_run
19//! use oxify_authn::*;
20//!
21//! # fn example() -> std::result::Result<(), Box<dyn std::error::Error>> {
22//! // Create JWT configuration
23//! let config = JwtConfig::development();
24//!
25//! // Create JWT manager
26//! let jwt_manager = JwtManager::new(&config)?;
27//!
28//! // Create a user
29//! let user = User {
30//!     username: "alice".to_string(),
31//!     roles: vec!["admin".to_string()],
32//!     email: Some("alice@example.com".to_string()),
33//!     full_name: Some("Alice Wonderland".to_string()),
34//!     last_login: None,
35//!     permissions: vec![Permission::Admin],
36//! };
37//!
38//! // Generate JWT token
39//! let token = jwt_manager.generate_token(&user)?;
40//!
41//! // Validate token
42//! let validation = jwt_manager.validate_token(&token)?;
43//! assert_eq!(validation.user.username, "alice");
44//! # Ok(())
45//! # }
46//! ```
47
48// Clippy pedantic lint configuration
49// These lints are allowed as "common allows" to maintain code clarity and API stability
50#![allow(clippy::missing_errors_doc)] // Would require 90+ doc additions without significant value
51#![allow(clippy::missing_panics_doc)] // Would require 36+ doc additions, panics are in error paths
52#![allow(clippy::unused_async)] // Async trait methods must remain async for API consistency
53#![allow(clippy::cast_possible_truncation)] // Intentional casts for time conversions (u64 to i64)
54#![allow(clippy::cast_precision_loss)] // Acceptable precision loss for metrics (usize/u64 to f64)
55#![allow(clippy::cast_sign_loss)] // Intentional for non-negative time calculations
56#![allow(clippy::cast_possible_wrap)] // Time calculations are within valid i64 range
57#![allow(clippy::struct_excessive_bools)] // Complex config structs need boolean flags
58#![allow(clippy::too_many_lines)] // Some parsing functions are necessarily long
59
60pub mod types;
61
62#[cfg(feature = "jwt")]
63pub mod jwt;
64
65#[cfg(feature = "password")]
66pub mod password;
67
68#[cfg(feature = "oauth")]
69pub mod oauth;
70
71#[cfg(feature = "mfa")]
72pub mod mfa;
73
74#[cfg(feature = "session")]
75pub mod session;
76
77#[cfg(feature = "revocation")]
78pub mod revocation;
79
80#[cfg(feature = "ratelimit")]
81pub mod ratelimit;
82
83#[cfg(feature = "saml")]
84pub mod saml;
85
86#[cfg(feature = "ldap")]
87pub mod ldap;
88
89#[cfg(feature = "webauthn")]
90pub mod webauthn;
91
92#[cfg(feature = "risk")]
93pub mod risk;
94
95#[cfg(feature = "rotation")]
96pub mod rotation;
97
98#[cfg(feature = "apikey")]
99pub mod apikey;
100
101#[cfg(feature = "metrics")]
102pub mod metrics;
103
104#[cfg(feature = "cert")]
105pub mod cert;
106
107#[cfg(feature = "idp")]
108pub mod idp;
109
110#[cfg(feature = "ai")]
111pub mod ai;
112
113// Re-export commonly used types
114pub use types::*;
115
116#[cfg(feature = "jwt")]
117pub use jwt::{ClaimsBuilder, JwtManager};
118
119#[cfg(feature = "password")]
120pub use password::{
121    PasswordManager, PasswordPolicy, PasswordStrength, PolicyValidationResult, PolicyViolation,
122};
123
124#[cfg(feature = "oauth")]
125pub use oauth::{OAuth2Service, OAuth2State, OAuth2Token, OIDCUserInfo};
126
127#[cfg(feature = "mfa")]
128pub use mfa::{TotpConfig, TotpEnrollment, TotpManager};
129
130#[cfg(feature = "session")]
131pub use session::{
132    InMemorySessionStore, Session, SessionConfig, SessionConfigBuilder, SessionInfo,
133    SessionManager, SessionStore,
134};
135
136#[cfg(feature = "revocation")]
137pub use revocation::{
138    InMemoryRevocationStore, RevocationConfig, RevocationConfigBuilder, RevocationEntry,
139    RevocationManager, RevocationReason, RevocationStats, RevocationStore,
140};
141
142#[cfg(feature = "ratelimit")]
143pub use ratelimit::{
144    RateLimitConfig, RateLimitConfigBuilder, RateLimitResult, RateLimitStatus, RateLimiter,
145    UserRateLimitStatus,
146};
147
148#[cfg(feature = "saml")]
149pub use saml::{Assertion, AuthnRequest, SamlError, ServiceProvider, SpConfig, SpConfigBuilder};
150
151#[cfg(feature = "ldap")]
152pub use ldap::{LdapAuthenticator, LdapConfig, LdapError, LdapUser};
153
154#[cfg(feature = "webauthn")]
155pub use webauthn::{
156    CredentialStore, InMemoryCredentialStore, StoredCredential, WebAuthnAuthenticator,
157    WebAuthnConfig, WebAuthnConfigBuilder, WebAuthnError,
158};
159
160#[cfg(feature = "risk")]
161pub use risk::{
162    DeviceFingerprint, GeoLocation, LoginContext, LoginContextBuilder, RiskAnalyzer,
163    RiskAssessment, RiskConfig, RiskLevel, RiskReason,
164};
165
166#[cfg(feature = "rotation")]
167pub use rotation::{
168    RefreshTokenMetadata, RotationConfig, RotationConfigBuilder, RotationManager, RotationStats,
169};
170
171#[cfg(feature = "apikey")]
172pub use apikey::{
173    ApiKeyConfig, ApiKeyManager, ApiKeyMetadata, ApiKeyScope, ApiKeyStats, ApiKeyValidation,
174    GeneratedApiKey,
175};
176
177#[cfg(feature = "metrics")]
178pub use metrics::{
179    AuthEvent, AuthEventRecord, AuthMetrics, GeoDistribution, MetricsCollector, TimeSeriesPoint,
180};
181
182#[cfg(feature = "cert")]
183pub use cert::{
184    CertAuthenticator, CertConfig, CertConfigBuilder, CertError, CertValidation, RevocationStatus,
185};
186
187#[cfg(feature = "idp")]
188pub use idp::{
189    discover_oidc, IdpClient, IdpConfig, IdpConfigBuilder, IdpError, IdpProvider, IdpUserInfo,
190    OidcDiscovery,
191};
192
193#[cfg(feature = "ai")]
194pub use ai::{
195    AiSecurityConfig, AiSecurityEngine, AiSecurityError, AiSecurityStats, AnomalyDetection,
196    BehaviorProfile, LoginEvent, TrustLevel,
197};
198
199#[cfg(test)]
200mod tests {
201    use super::*;
202
203    #[test]
204    fn test_basic_types() {
205        let user = User {
206            username: "test".to_string(),
207            roles: vec!["user".to_string()],
208            email: None,
209            full_name: None,
210            last_login: None,
211            permissions: vec![],
212        };
213
214        assert_eq!(user.username, "test");
215    }
216}