Skip to main content

gitv_tui/auth/
keyring.rs

1use crate::auth::AuthProvider;
2use crate::errors::AppError;
3
4pub struct KeyringAuth {
5    service: String,
6}
7
8impl KeyringAuth {
9    pub fn new(service: &str) -> Result<Self, AppError> {
10        Ok(Self {
11            service: service.to_string(),
12        })
13    }
14}
15
16impl AuthProvider for KeyringAuth {
17    fn get_token(&self) -> Result<String, AppError> {
18        let entry = keyring::Entry::new(&self.service, "github")?;
19        let token = entry.get_password()?;
20        Ok(token)
21    }
22    fn set_token(&self, token: &str) -> Result<(), AppError> {
23        let entry = keyring::Entry::new(&self.service, "github")?;
24        entry.set_password(token)?;
25
26        Ok(())
27    }
28}