oauth_device_flows/lib.rs
1//! # OAuth Device Flows
2//!
3//! A specialized Rust library that implements the OAuth 2.0 Device Authorization Grant (RFC 8628),
4//! commonly known as the "device flow" or "device code flow". This authentication flow is
5//! particularly useful for devices with limited input capabilities, headless systems, or CLI
6//! applications where redirecting to a browser is impractical.
7//!
8//! ## Features
9//!
10//! - Complete implementation of the OAuth 2.0 Device Authorization Grant
11//! - Support for multiple OAuth providers (Microsoft, Google, GitHub, etc.)
12//! - Customizable polling strategies with exponential backoff
13//! - Token caching and refresh mechanisms
14//! - Strong typing for OAuth responses
15//! - Comprehensive error handling and recovery
16//! - Minimal dependencies for embedded use
17//! - Async/await support
18//! - Custom URI handling for verification
19//! - QR code generation for device code display (optional feature)
20//!
21//! ## Quick Start
22//!
23//! ```rust,no_run
24//! use oauth_device_flows::{DeviceFlow, DeviceFlowConfig, Provider};
25//! use std::time::Duration;
26//!
27//! #[tokio::main]
28//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
29//! // Configure the device flow
30//! let config = DeviceFlowConfig::new()
31//! .client_id("your-client-id")
32//! .scopes(vec!["user.read", "offline_access"])
33//! .poll_interval(Duration::from_secs(5))
34//! .max_attempts(12);
35//!
36//! // Create a device flow instance for Microsoft
37//! let mut device_flow = DeviceFlow::new(Provider::Microsoft, config)?;
38//!
39//! // Start the device authorization flow
40//! let auth_response = device_flow.initialize().await?;
41//!
42//! // Display information to the user
43//! println!("To sign in, use a web browser to open the page {} and enter the code {} to authenticate.",
44//! auth_response.verification_uri(),
45//! auth_response.user_code());
46//!
47//! // Poll for the token
48//! println!("Waiting for authentication...");
49//! let token_response = device_flow.poll_for_token().await?;
50//!
51//! println!("Successfully authenticated!");
52//! Ok(())
53//! }
54//! ```
55
56pub mod config;
57pub mod device_flow;
58pub mod error;
59pub mod provider;
60pub mod token;
61pub mod types;
62
63pub use config::DeviceFlowConfig;
64pub use device_flow::DeviceFlow;
65pub use error::{DeviceFlowError, Result};
66pub use provider::Provider;
67pub use token::TokenManager;
68pub use types::{AuthorizationResponse, TokenResponse};