//! OAuth2 provider implementations. //! //! Implements OAuth2 authentication for various email providers: //! - Fastmail (JMAP) //! - Google/Gmail (Gmail API + IMAP XOAUTH2) //! - Microsoft/Outlook (Graph API + IMAP XOAUTH2) pub mod fastmail; pub mod google; pub mod microsoft; pub use fastmail::FastmailProvider; pub use google::GoogleProvider; pub use microsoft::MicrosoftProvider; use super::provider::OAuthProvider; use goingson_core::EmailAuthType; /// Registry of all supported OAuth providers. pub struct ProviderRegistry { providers: Vec>, } impl ProviderRegistry { /// Creates a new provider registry with default provider configurations. /// /// Client IDs should be loaded from environment or configuration. pub fn new(config: ProviderConfig) -> Self { let mut providers: Vec> = Vec::new(); if let Some(client_id) = config.fastmail_client_id { providers.push(Box::new(FastmailProvider::new(client_id))); } if let (Some(client_id), Some(client_secret)) = (config.google_client_id, config.google_client_secret) { providers.push(Box::new(GoogleProvider::new(client_id, client_secret))); } if let Some(client_id) = config.microsoft_client_id { providers.push(Box::new(MicrosoftProvider::new(client_id, config.microsoft_client_secret))); } Self { providers } } /// Returns a list of available provider IDs. pub fn available_providers(&self) -> Vec<&'static str> { self.providers.iter().map(|p| p.id()).collect() } /// Gets a provider by its ID. pub fn get(&self, id: &str) -> Option<&dyn OAuthProvider> { self.providers.iter().find(|p| p.id() == id).map(|p| p.as_ref()) } /// Gets the auth type for a provider ID. pub fn auth_type_for(id: &str) -> EmailAuthType { match id { "fastmail" => EmailAuthType::OAuth2Fastmail, // Future providers will have their own EmailAuthType variants _ => EmailAuthType::Password, } } } /// Configuration for OAuth providers. /// /// Client IDs and secrets should be loaded from environment variables /// or a configuration file. #[derive(Debug, Clone, Default)] pub struct ProviderConfig { /// Fastmail OAuth client ID. pub fastmail_client_id: Option, /// Google OAuth client ID. pub google_client_id: Option, /// Google OAuth client secret. pub google_client_secret: Option, /// Microsoft OAuth client ID. pub microsoft_client_id: Option, /// Microsoft OAuth client secret. pub microsoft_client_secret: Option, } impl ProviderConfig { /// Loads provider configuration from environment variables. pub fn from_env() -> Self { Self { fastmail_client_id: std::env::var("GOINGSON_FASTMAIL_CLIENT_ID").ok(), google_client_id: std::env::var("GOINGSON_GOOGLE_CLIENT_ID").ok(), google_client_secret: std::env::var("GOINGSON_GOOGLE_CLIENT_SECRET").ok(), microsoft_client_id: std::env::var("GOINGSON_MICROSOFT_CLIENT_ID").ok(), microsoft_client_secret: std::env::var("GOINGSON_MICROSOFT_CLIENT_SECRET").ok(), } } }