Examples

Basic Examples

Offline Authentication

use lighty_auth::{offline::OfflineAuth, Authenticator};

#[tokio::main]
async fn main()  {
    let mut auth = OfflineAuth::new("Steve");
    let profile = auth.authenticate().await?;

    println!("Username: {}", profile.username);
    println!("UUID: {}", profile.uuid);

    Ok(())
}

Microsoft Authentication

use lighty_auth::{microsoft::MicrosoftAuth, Authenticator};

#[tokio::main]
async fn main()  {
    let mut auth = MicrosoftAuth::new("your-azure-client-id");

    auth.set_device_code_callback(|code, url| {
        println!("Visit {} and enter: {}", url, code);
    });

    let profile = auth.authenticate().await?;
    println!("Logged in as: {}", profile.username);

    Ok(())
}

Azuriom Authentication

Advanced Examples

Multi-Provider Launcher

Support multiple authentication methods:

Azuriom with 2FA

Handle two-factor authentication:

Token Caching and Verification

Cache authentication tokens to avoid re-authentication:

Event-Driven Authentication UI

Track authentication progress for UI updates:

Retry on Network Failure

Robust authentication with automatic retry:

Custom Authentication Provider

Implement your own authentication backend:

Parallel Authentication Attempts

Try multiple auth methods simultaneously:

Session Management

Complete session lifecycle management:

See Also

Last updated