use immich_sdk::{Client, Config}; use std::time::Duration; use immich_sdk::models::{OAuthConfigDto, OAuthCallbackDto}; #[tokio::main] async fn main() -> Result<(), Box> { let config = Config::new("http://localhost:2283") .with_api_key("your-api-key") .with_timeout(Duration::from_secs(30)); let client = Client::new(config)?; println!("Starting OAuth authorization process..."); // 1. Start OAuth authorization // In a real scenario, this URL would be opened in a browser. let auth_config = OAuthConfigDto { redirect_uri: "http://localhost:8080/callback".to_string(), code_challenge: None, state: Some("random_state_string".to_string()), }; let auth_response = client .oauth() .authorize(auth_config) .await?; let auth_url = auth_response.url; println!("Please visit this URL to authorize: {}", auth_url); // 2. Simulate the callback from the OAuth provider // In a real scenario, your web server would receive this POST request. let callback_data = OAuthCallbackDto { url: "http://localhost:8080/callback".to_string(), state: Some("random_state_string".to_string()), code_verifier: Some("some_verifier".to_string()), }; println!("Simulating OAuth callback with: {:?}", callback_data); // 3. Finish OAuth process by exchanging the code for a session token let login_response = client .oauth() .finish_oauth(callback_data) .await?; println!("Successfully logged in!"); println!("Access Token: {}", login_response.access_token); println!("User ID: {}", login_response.user_id); println!("User Email: {}", login_response.user_email); Ok(()) }