pub struct SessionManager { /* private fields */ }Expand description
Session manager for handling authentication sessions
API keys are stored securely via the KeyStore trait (system keyring, encrypted file, etc.).
The session file only contains non-sensitive metadata.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(session_file: PathBuf, key_store: Option<Box<dyn KeyStore>>) -> Self
pub fn new(session_file: PathBuf, key_store: Option<Box<dyn KeyStore>>) -> Self
Create a new session manager
§Arguments
session_file- Path to the session JSON filekey_store- Optional secure key store for API keys. If None, API keys are stored in the session file as a fallback.
Sourcepub fn load(&self) -> Result<Option<AuthSession>>
pub fn load(&self) -> Result<Option<AuthSession>>
Load session from disk
Sourcepub fn save(&self, session: &AuthSession, api_key: Option<&str>) -> Result<()>
pub fn save(&self, session: &AuthSession, api_key: Option<&str>) -> Result<()>
Save session to disk and optionally store API key in key store
The API key is stored in the key store if available, not in the session file.
Sourcepub fn is_authenticated(&self) -> Result<bool>
pub fn is_authenticated(&self) -> Result<bool>
Check if user is authenticated (has valid session)
Sourcepub fn get_session(&self) -> Result<Option<AuthSession>>
pub fn get_session(&self) -> Result<Option<AuthSession>>
Get the current session if valid
Sourcepub fn get_api_key(&self) -> Result<Option<Zeroizing<String>>>
pub fn get_api_key(&self) -> Result<Option<Zeroizing<String>>>
Get the API key for the current session
Tries key store first, falls back to session file for backwards compatibility. Returns Zeroizing to ensure key is cleared from memory when dropped.
Sourcepub fn create_session(
response: AuthResponse,
backend: String,
_api_key: String,
) -> AuthSession
pub fn create_session( response: AuthResponse, backend: String, _api_key: String, ) -> AuthSession
Create session from authentication response
Sourcepub fn migrate_to_key_store(&self) -> Result<bool>
pub fn migrate_to_key_store(&self) -> Result<bool>
Migrate legacy session (with api_key in file) to key store
Call this during login to migrate old sessions to secure storage.
Sourcepub fn session_file(&self) -> &Path
pub fn session_file(&self) -> &Path
Get the session file path