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§
- Auth
Service - Service for handling authentication flows
- Credentials
Service - 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