Crate mecha10_auth

Crate mecha10_auth 

Source
Expand description

Mecha10 Authentication Library

Shared authentication services for CLI and launcher.

§Features

  • Device code OAuth 2.0 flow (RFC 8628) for browser-based authentication
  • Credentials storage at ~/.mecha10/credentials.json
  • Support for custom auth server URLs via MECHA10_AUTH_URL environment variable

§Usage

use mecha10_auth::{AuthService, CredentialsService};

async fn login() -> anyhow::Result<()> {
    let auth_service = AuthService::new();
    let credentials_service = CredentialsService::new();

    // Run device code flow
    let credentials = auth_service.run_device_code_flow(|device_code| {
        println!("Go to: {}", device_code.verification_uri);
        println!("Enter code: {}", device_code.user_code);
    }).await?;

    // Save credentials
    credentials_service.save(&credentials)?;
    Ok(())
}

Re-exports§

pub use types::AuthError;
pub use types::Credentials;
pub use types::DeviceCodeResponse;
pub use types::DeviceCodeStatus;

Modules§

types
Authentication type definitions

Structs§

AuthService
Service for handling authentication flows
CredentialsService
Service for managing user credentials

Constants§

AUTH_URL_ENV_VAR
Environment variable name for custom auth URL
DEFAULT_AUTH_URL
Default auth URL for production

Functions§

default_credentials_path
Get the default credentials path (~/.mecha10/credentials.json)
display_device_code_instructions
Display the device code flow instructions in a formatted box
get_auth_url
Get the auth URL, checking environment variable first
open_browser
Try to open the verification URL in the default browser