Something went wrong. Try again.
AtAuth forked from bkb.arcnode.xyz/atauth
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596//! # ATAuth - AT Protocol Authentication Library//!//! A generic, plug-and-play authentication library for AT Protocol (Bluesky) OAuth integration.//!//! ## Features//!//! - **Token Verification**: Secure HMAC-SHA256 token verification with constant-time comparison//! - **Session Management**: Trait-based session storage with SQLite backend//! - **Rate Limiting**: IP-based rate limiting with configurable thresholds//! - **Input Validation**: DID and handle format validation//!//! ## Quick Start//!//! ```rust,no_run//! use atauth::{TokenVerifier, TokenPayload};//!//! // Create a verifier with your HMAC secret (must be at least 32 bytes)//! let verifier = TokenVerifier::new(b"your-secret-key-at-least-32-bytes!!")//! .expect("Secret must be at least 32 bytes");//!//! // Verify a token from the auth gateway//! match verifier.verify("token-from-gateway") {//! Ok(payload) => {//! println!("Authenticated user: {} ({})", payload.handle, payload.did);//! }//! Err(e) => {//! eprintln!("Authentication failed: {}", e);//! }//! }//! ```//!//! ## With Session Store//!//! ```rust,ignore//! use atauth::{TokenVerifier, SessionManager};//! use atauth::session::SqliteSessionStore;//!//! let verifier = TokenVerifier::new(b"your-secret-key");//! let session_store = SqliteSessionStore::new("sessions.db")?;//! let session_manager = SessionManager::new(session_store);//!//! // On successful token verification//! if let Ok(payload) = verifier.verify(token) {//! session_manager.create_session(&payload)?;//! }//! ```
pub mod error;pub mod token;pub mod validation;
#[cfg(feature = "session-sqlite")]pub mod session;
#[cfg(feature = "rate-limit")]pub mod rate_limit;
// Re-exports for conveniencepub use error::{AuthError, AuthResult};pub use token::{TokenPayload, TokenVerifier};pub use validation::{validate_did, validate_handle};
#[cfg(feature = "session-sqlite")]pub use session::{Session, SessionManager, SessionStore};
#[cfg(feature = "rate-limit")]pub use rate_limit::{RateLimiter, RateLimiterConfig};
/// Library versionpub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// Maximum token length (prevents DoS via large tokens)pub const MAX_TOKEN_LENGTH: usize = 2048;
/// Maximum DID length per AT Protocol specpub const MAX_DID_LENGTH: usize = 512;
/// Maximum handle lengthpub const MAX_HANDLE_LENGTH: usize = 256;
/// Minimum secret key length (32 bytes = 256 bits for HMAC-SHA256 security)pub const MIN_SECRET_LENGTH: usize = 32;
/// Prelude module for common importspub mod prelude { pub use crate::error::{AuthError, AuthResult}; pub use crate::token::{TokenPayload, TokenVerifier}; pub use crate::validation::{validate_did, validate_handle};
#[cfg(feature = "session-sqlite")] pub use crate::session::{Session, SessionManager, SessionStore};
#[cfg(feature = "rate-limit")] pub use crate::rate_limit::{RateLimiter, RateLimiterConfig};}