Skip to main content

aether_auth/
credential.rs

1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3
4use crate::OAuthError;
5
6/// Credential for an OAuth provider.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct OAuthCredential {
9    pub client_id: String,
10    pub access_token: String,
11    pub refresh_token: Option<String>,
12    /// Unix timestamp in milliseconds when the token expires.
13    pub expires_at: Option<u64>,
14}
15
16/// Trait for loading and saving OAuth credentials, keyed by provider ID or credential key.
17///
18/// Implementations include [`OsKeyringStore`](crate::OsKeyringStore) (OS keychain, feature `keyring`)
19/// and the in-memory [`FakeOAuthCredentialStore`](crate::FakeOAuthCredentialStore) for tests.
20#[async_trait]
21pub trait OAuthCredentialStorage: Send + Sync {
22    async fn load_credential(&self, key: &str) -> Result<Option<OAuthCredential>, OAuthError>;
23
24    async fn save_credential(&self, key: &str, credential: OAuthCredential) -> Result<(), OAuthError>;
25
26    async fn delete_credential(&self, key: &str) -> Result<(), OAuthError>;
27
28    fn has_credential(&self, key: &str) -> bool;
29}