lighty_auth/
lib.rs

1// Copyright (c) 2025 Hamadi
2// Licensed under the MIT License
3
4//! Authentication module for Lighty Launcher
5//!
6//! Provides multiple authentication providers and a trait-based system for custom implementations.
7//!
8//! ## Built-in Providers
9//!
10//! - **Offline**: No network authentication, generates deterministic UUIDs from username
11//! - **Microsoft**: OAuth 2.0 authentication via Microsoft/Xbox Live
12//! - **Azuriom**: Authentication via Azuriom CMS API
13//!
14//! ## Custom Authentication
15//!
16//! Implement the `Authenticator` trait to create your own authentication provider:
17//!
18//! ```rust
19//! use lighty_auth::{Authenticator, UserProfile, UserRole, AuthResult, AuthError};
20//! # use async_trait::async_trait;
21//!
22//! pub struct MyCustomAuth {
23//!     api_url: String,
24//!     username: String,
25//! }
26//!
27//! impl MyCustomAuth {
28//!     pub fn new(api_url: String, username: String) -> Self {
29//!         Self { api_url, username }
30//!     }
31//! }
32//!
33//! impl Authenticator for MyCustomAuth {
34//!     async fn authenticate(
35//!         &mut self,
36//!         #[cfg(feature = "events")] event_bus: Option<&lighty_event::EventBus>,
37//!     ) -> AuthResult<UserProfile> {
38//!         // Your custom authentication logic here
39//!
40//!         // Example: make HTTP request to your API
41//!         // let response = reqwest::get(&self.api_url).await?;
42//!         // let data = response.json::<YourResponse>().await?;
43//!
44//!         Ok(UserProfile {
45//!             username: self.username.clone(),
46//!             uuid: "your-uuid".to_string(),
47//!             access_token: Some("your-token".to_string()),
48//!             role: UserRole::User,
49//!         })
50//!     }
51//! }
52//! ```
53//!
54//! ## Helpers
55//!
56//! Use the `generate_offline_uuid()` function to create deterministic UUIDs:
57//!
58//! ```rust
59//! use lighty_auth::generate_offline_uuid;
60//!
61//! let uuid = generate_offline_uuid("PlayerName");
62//! println!("UUID: {}", uuid); // Always the same for this username
63//! ```
64
65mod auth;
66mod errors;
67
68pub mod offline;
69pub mod azuriom;
70pub mod microsoft;
71
72// Re-export core types
73pub use auth::{
74    AuthProvider, AuthResult, Authenticator, UserProfile, UserRole, generate_offline_uuid,
75};
76pub use errors::AuthError;