use std::sync::Arc; use cache::redis::RedisCache; use db::conn::Db; use email::EmailService; use jwt::{HasJwtState, JwtState}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::config::{AuthConfig, SharedAuthConfig}; use crate::pow::PowService; pub mod agreement; pub mod email_code; pub mod forgot_password; pub mod login; pub mod logout; pub mod oauth; pub mod password_hash; pub mod reclaim; pub mod refresh; pub mod register; pub mod resend_code; pub mod reset_password; #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct TempKey { pub name: String, pub value: String, pub ttl_seconds: u64, pub secure: bool, pub http_only: bool, pub same_site: String, pub domain: Option, pub path: Option, } #[derive(Clone)] pub struct AuthService { pub db: Db, pub email: EmailService, pub kv: Arc, pub pow: PowService, pub config: SharedAuthConfig, pub jwt: JwtState, } impl AuthService { pub fn new( db: Db, email: EmailService, kv: Arc, pow: PowService, config: AuthConfig, jwt: JwtState, ) -> Self { Self { db, email, pow: pow.with_kv(kv.clone()), kv, config: Arc::new(config), jwt, } } pub fn with_config(mut self, config: SharedAuthConfig) -> Self { self.config = config; self } } impl HasJwtState for AuthService { fn jwt_state(&self) -> &JwtState { &self.jwt } fn access_blacklist(&self) -> Option> { Some(Arc::new(rate_limit::AccessTokenBlacklist::new( self.kv.clone(), ))) } } impl rate_limit::RateLimitProvider for AuthService { fn rate_limit_kv(&self) -> Arc { self.kv.clone() } fn rate_limit_settings(&self) -> Arc { Arc::new(rate_limit::RateLimitConfig { cookie_secure: self.config.cookie_secure, ..rate_limit::RateLimitConfig::default() }) } }