diff options
-rw-r--r-- | src/actions.rs | 17 | ||||
-rw-r--r-- | src/api.rs | 24 | ||||
-rw-r--r-- | src/bin/rbw-agent/actions.rs | 11 | ||||
-rw-r--r-- | src/db.rs | 1 |
4 files changed, 46 insertions, 7 deletions
diff --git a/src/actions.rs b/src/actions.rs index 9284677..b891670 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -49,7 +49,15 @@ pub async fn unlock( pub async fn sync( access_token: &str, refresh_token: &str, -) -> Result<(Option<String>, (String, String, Vec<crate::db::Entry>))> { +) -> Result<( + Option<String>, + ( + String, + String, + std::collections::HashMap<String, String>, + Vec<crate::db::Entry>, + ), +)> { with_exchange_refresh_token_async( access_token, refresh_token, @@ -63,7 +71,12 @@ pub async fn sync( async fn sync_once( access_token: &str, -) -> Result<(String, String, Vec<crate::db::Entry>)> { +) -> Result<( + String, + String, + std::collections::HashMap<String, String>, + Vec<crate::db::Entry>, +)> { let config = crate::config::Config::load_async().await?; let client = crate::api::Client::new(&config.base_url(), &config.identity_url()); @@ -148,6 +148,16 @@ struct SyncResProfile { key: String, #[serde(rename = "PrivateKey")] private_key: String, + #[serde(rename = "Organizations")] + organizations: Vec<SyncResProfileOrganization>, +} + +#[derive(serde::Deserialize, Debug)] +struct SyncResProfileOrganization { + #[serde(rename = "Id")] + id: String, + #[serde(rename = "Key")] + key: String, } #[derive(serde::Deserialize, Debug, Clone)] @@ -321,7 +331,12 @@ impl Client { pub async fn sync( &self, access_token: &str, - ) -> Result<(String, String, Vec<crate::db::Entry>)> { + ) -> Result<( + String, + String, + std::collections::HashMap<String, String>, + Vec<crate::db::Entry>, + )> { let client = reqwest::Client::new(); let res = client .get(&self.api_url("/sync")) @@ -339,9 +354,16 @@ impl Client { .iter() .filter_map(|cipher| cipher.to_entry(&folders)) .collect(); + let org_keys = sync_res + .profile + .organizations + .iter() + .map(|org| (org.id.clone(), org.key.clone())) + .collect(); Ok(( sync_res.profile.key, sync_res.profile.private_key, + org_keys, ciphers, )) } diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs index 5b3444d..e24d044 100644 --- a/src/bin/rbw-agent/actions.rs +++ b/src/bin/rbw-agent/actions.rs @@ -189,15 +189,18 @@ pub async fn sync(sock: &mut crate::sock::Sock) -> anyhow::Result<()> { } else { return Err(anyhow::anyhow!("failed to find refresh token in db")); }; - let (access_token, (protected_key, protected_private_key, entries)) = - rbw::actions::sync(&access_token, &refresh_token) - .await - .context("failed to sync database from server")?; + let ( + access_token, + (protected_key, protected_private_key, protected_org_keys, entries), + ) = rbw::actions::sync(&access_token, &refresh_token) + .await + .context("failed to sync database from server")?; if let Some(access_token) = access_token { db.access_token = Some(access_token); } db.protected_key = Some(protected_key); db.protected_private_key = Some(protected_private_key); + db.protected_org_keys = protected_org_keys; db.entries = entries; db.save_async(&email) .await @@ -33,6 +33,7 @@ pub struct Db { pub iterations: Option<u32>, pub protected_key: Option<String>, pub protected_private_key: Option<String>, + pub protected_org_keys: std::collections::HashMap<String, String>, pub entries: Vec<Entry>, } |