Crate lighty_auth

Crate lighty_auth 

Source
Expand description

Authentication module for Lighty Launcher

Provides multiple authentication providers and a trait-based system for custom implementations.

§Built-in Providers

  • Offline: No network authentication, generates deterministic UUIDs from username
  • Microsoft: OAuth 2.0 authentication via Microsoft/Xbox Live
  • Azuriom: Authentication via Azuriom CMS API

§Custom Authentication

Implement the Authenticator trait to create your own authentication provider:

use lighty_auth::{Authenticator, UserProfile, UserRole, AuthResult, AuthError};

pub struct MyCustomAuth {
    api_url: String,
    username: String,
}

impl MyCustomAuth {
    pub fn new(api_url: String, username: String) -> Self {
        Self { api_url, username }
    }
}

impl Authenticator for MyCustomAuth {
    async fn authenticate(
        &mut self,
        #[cfg(feature = "events")] event_bus: Option<&lighty_event::EventBus>,
    ) -> AuthResult<UserProfile> {
        // Your custom authentication logic here

        // Example: make HTTP request to your API
        // let response = reqwest::get(&self.api_url).await?;
        // let data = response.json::<YourResponse>().await?;

        Ok(UserProfile {
            username: self.username.clone(),
            uuid: "your-uuid".to_string(),
            access_token: Some("your-token".to_string()),
            role: UserRole::User,
        })
    }
}

§Helpers

Use the generate_offline_uuid() function to create deterministic UUIDs:

use lighty_auth::generate_offline_uuid;

let uuid = generate_offline_uuid("PlayerName");
println!("UUID: {}", uuid); // Always the same for this username

Modules§

azuriom
Azuriom CMS authentication
microsoft
Microsoft OAuth 2.0 authentication for Minecraft
offline
Offline authentication - no network required

Structs§

UserProfile
User profile returned after successful authentication
UserRole
User role/rank information

Enums§

AuthError
Authentication errors
AuthProvider
Authentication provider type

Traits§

Authenticator
Core authentication trait

Functions§

generate_offline_uuid
Helper to generate UUID v5 from username (for offline mode)

Type Aliases§

AuthResult