Events

Overview

lighty-auth emits AuthEvent types through the event bus system provided by lighty-event. These events track authentication flow progress.

Feature: Requires events feature flag

Export:

  • Event types: lighty_event::AuthEvent

  • Re-export: lighty_launcher::event::AuthEvent

AuthEvent Types

AuthenticationStarted

Emitted when authentication process begins.

Fields:

  • provider: AuthProvider - The authentication provider being used

When emitted: At the start of any authenticate() call

Example:

use lighty_event::{EventBus, Event, AuthEvent};
use lighty_auth::{offline::OfflineAuth, Authenticator};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let event_bus = EventBus::new(1000);
    let mut receiver = event_bus.subscribe();

    tokio::spawn(async move {
        while let Ok(event) = receiver.next().await {
            if let Event::Auth(AuthEvent::AuthenticationStarted { provider }) = event {
                println!("Starting authentication with: {:?}", provider);
            }
        }
    });

    let mut auth = OfflineAuth::new("Player");
    auth.authenticate(Some(&event_bus)).await?;

    Ok(())
}

DeviceCodeReceived

Emitted when Microsoft device code is received (Microsoft only).

Fields:

  • code: String - The device code to display to user

  • url: String - The URL user should visit

  • expires_in: u64 - Seconds until code expires

When emitted: During Microsoft authentication after device code request

Example:

WaitingForUser

Emitted while polling for user to complete authentication.

Fields: None

When emitted: During Microsoft authentication polling loop

Example:

AuthenticationSuccess

Emitted when authentication completes successfully.

Fields:

  • username: String - Authenticated username

  • provider: AuthProvider - Provider used

When emitted: After successful authentication, before returning profile

Example:

AuthenticationFailed

Emitted when authentication fails.

Fields:

  • error: String - Error message

  • provider: AuthProvider - Provider that failed

When emitted: When authentication fails with error

Example:

Complete Event Flow

Offline Authentication

Microsoft Authentication (Success)

Microsoft Authentication (Failure)

Azuriom Authentication

Last updated