Skip to main content

eero_api/credential/
mod.rs

1//! Pluggable credential storage for eero session tokens.
2//!
3//! The [`CredentialStore`] trait defines how session and user tokens are
4//! persisted. Multiple implementations are provided:
5//!
6//! - [`file::FileStore`] — Plain text files (default)
7//! - [`memory::InMemoryStore`] — Non-persistent, for testing
8//! - `keyring::KeyringStore` — OS keychain (feature `keyring`)
9//! - `op::OpStore` — 1Password CLI (feature `op`)
10//! - `dpapi::DpapiStore` — Windows DPAPI (feature `dpapi`, Windows only)
11
12pub mod file;
13pub mod memory;
14#[cfg(feature = "keyring")]
15pub mod keyring;
16#[cfg(feature = "op")]
17pub mod op;
18#[cfg(all(feature = "dpapi", target_os = "windows"))]
19pub mod dpapi;
20
21use crate::error::Result;
22
23/// Trait for storing and retrieving eero authentication tokens.
24///
25/// Implementations must be `Send + Sync` for use with async code.
26/// Two token types are managed:
27///
28/// - **Session token** — Long-lived token used for API requests
29/// - **User token** — Temporary token from login, exchanged during verify
30#[async_trait::async_trait]
31pub trait CredentialStore: Send + Sync {
32    /// Retrieve the stored session token, if any.
33    async fn get_session_token(&self) -> Result<Option<String>>;
34    /// Store a session token.
35    async fn set_session_token(&self, token: &str) -> Result<()>;
36    /// Delete the stored session token.
37    async fn delete_session_token(&self) -> Result<()>;
38    /// Retrieve the stored user token, if any.
39    async fn get_user_token(&self) -> Result<Option<String>>;
40    /// Store a user token.
41    async fn set_user_token(&self, token: &str) -> Result<()>;
42    /// Delete the stored user token.
43    async fn delete_user_token(&self) -> Result<()>;
44}