YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(connections): support multiple OAuth accounts for Zoom (#4328)
Ansh Grover1a4651646a8c
diff --git a/apps/screenpipe-app-tauri/components/settings/connections-section.tsx b/apps/screenpipe-app-tauri/components/settings/connections-section.tsxindex ddde29514..9e4bb7043 100644--- a/apps/screenpipe-app-tauri/components/settings/connections-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/connections-section.tsx@@ -2240,11 +2240,13 @@ const OAUTH_SCOPE_VARIANTS: Record<function OAuthPanel({integrationId,integrationName,+ supportsOAuthInstances,onConnected,onDisconnected,}: {integrationId: string;integrationName: string;+ supportsOAuthInstances: boolean;onConnected?: () => void;onDisconnected?: () => void;}) {@@ -2348,6 +2350,7 @@ function OAuthPanel({};const connected = accounts.length > 0;+ const connectDisabled = isSubdomainProvider && !subdomain.trim();return (<div className="space-y-3">@@ -2436,9 +2439,11 @@ function OAuthPanel({</Button></div>) : (- <Button onClick={handleConnect} disabled={isSubdomainProvider && !subdomain.trim()} size="sm" className="gap-1.5 h-7 text-xs normal-case font-sans tracking-normal whitespace-nowrap">- {connected+ <Button onClick={handleConnect} disabled={connectDisabled} size="sm" className="gap-1.5 h-7 text-xs normal-case font-sans tracking-normal whitespace-nowrap">+ {connected && supportsOAuthInstances? (<><Plus className="h-3 w-3" />add another account</>)+ : connected+ ? (<><LogIn className="h-3 w-3" />reconnect {integrationName}</>): (<><LogIn className="h-3 w-3" />connect with {integrationName}</>)}</Button>)}@@ -2468,6 +2473,7 @@ export interface IntegrationInfo {fields: IntegrationField[];connected: boolean;is_oauth: boolean;+ supports_oauth_instances: boolean;}// ---------------------------------------------------------------------------@@ -3892,6 +3898,7 @@ export function ConnectionsSection({<OAuthPanelintegrationId={selectedIntegration.id}integrationName={selectedIntegration.name}+ supportsOAuthInstances={!!selectedIntegration.supports_oauth_instances}onConnected={() => refreshIntegrationConnection(selectedIntegration.id, true)}onDisconnected={() => refreshIntegrationConnection(selectedIntegration.id, false)}/>diff --git a/apps/screenpipe-app-tauri/src-tauri/src/oauth.rs b/apps/screenpipe-app-tauri/src-tauri/src/oauth.rsindex 63552b4ef..bd0149772 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/oauth.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/oauth.rs@@ -463,7 +463,7 @@ pub async fn oauth_connect(// We only fall back to the default slot (None) when the provider hands us// no identity to key on (e.g. Notion/QuickBooks/Jira, which key on// workspace metadata instead and stay single-account here).- let effective_instance = instance.or_else(|| token_data["email"].as_str().map(String::from));+ let effective_instance = derive_effective_instance(instance, &token_data);let store_instance = effective_instance.as_deref();oauth::write_oauth_token_instance(store.as_ref(), &integration_id, store_instance, &token_data)@@ -647,7 +647,48 @@ pub async fn oauth_list_instances(/// Extract email from an id_token JWT by decoding the payload (no signature verification).fn extract_email_from_jwt(jwt: &str) -> Option<String> {- decode_jwt_payload(jwt)?["email"].as_str().map(String::from)+ let payload = decode_jwt_payload(jwt)?;+ payload["email"]+ .as_str()+ .or_else(|| payload["preferred_username"].as_str())+ .or_else(|| payload["upn"].as_str())+ .map(String::from)+}++fn derive_effective_instance(+ explicit_instance: Option<String>,+ token_data: &serde_json::Value,+) -> Option<String> {+ explicit_instance.or_else(|| token_data["email"].as_str().map(String::from))+}++#[cfg(test)]+mod tests {+ use super::derive_effective_instance;+ use serde_json::json;++ #[test]+ fn effective_instance_uses_email_identity() {+ let token_data = json!({+ "access_token": "at",+ "email": "[email protected]",+ });++ assert_eq!(+ derive_effective_instance(None, &token_data).as_deref(),+ Some("[email protected]")+ );+ }++ #[test]+ fn effective_instance_does_not_use_workspace_metadata() {+ let token_data = json!({+ "access_token": "at",+ "workspace_name": "Acme Workspace",+ });++ assert_eq!(derive_effective_instance(None, &token_data), None);+ }}/// Microsoft's well-known tenant ID for **personal** Microsoft accounts@@ -727,6 +768,61 @@ async fn fetch_provider_identity(.or_else(|| resp["user"]["username"].as_str()).map(String::from)}+ "calcom" => {+ let resp: serde_json::Value = client+ .get("https://api.cal.com/v2/me")+ .bearer_auth(access_token)+ .header("cal-api-version", "2024-08-13")+ .send()+ .await+ .ok()?+ .error_for_status()+ .ok()?+ .json()+ .await+ .ok()?;+ let data = &resp["data"];+ data["email"]+ .as_str()+ .or_else(|| data["username"].as_str())+ .or_else(|| data["id"].as_str())+ .map(String::from)+ }+ "calendly" => {+ let resp: serde_json::Value = client+ .get("https://api.calendly.com/users/me")+ .bearer_auth(access_token)+ .send()+ .await+ .ok()?+ .error_for_status()+ .ok()?+ .json()+ .await+ .ok()?;+ let resource = &resp["resource"];+ resource["email"]+ .as_str()+ .or_else(|| resource["uri"].as_str())+ .map(String::from)+ }+ "zoom" => {+ let resp: serde_json::Value = client+ .get("https://api.zoom.us/v2/users/me")+ .bearer_auth(access_token)+ .send()+ .await+ .ok()?+ .error_for_status()+ .ok()?+ .json()+ .await+ .ok()?;+ resp["email"]+ .as_str()+ .or_else(|| resp["id"].as_str())+ .map(String::from)+ }_ => None,}}diff --git a/crates/screenpipe-connect/src/connections/calcom.rs b/crates/screenpipe-connect/src/connections/calcom.rsindex 26e9e30c0..a794d1c0d 100644--- a/crates/screenpipe-connect/src/connections/calcom.rs+++ b/crates/screenpipe-connect/src/connections/calcom.rs@@ -54,6 +54,10 @@ impl Integration for CalCom {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://api.cal.com/v2",diff --git a/crates/screenpipe-connect/src/connections/calendly.rs b/crates/screenpipe-connect/src/connections/calendly.rsindex 6123d382b..ada314ed4 100644--- a/crates/screenpipe-connect/src/connections/calendly.rs+++ b/crates/screenpipe-connect/src/connections/calendly.rs@@ -40,6 +40,10 @@ impl Integration for Calendly {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://api.calendly.com",diff --git a/crates/screenpipe-connect/src/connections/github_issues.rs b/crates/screenpipe-connect/src/connections/github_issues.rsindex a4c0a9c93..3e1e2a685 100644--- a/crates/screenpipe-connect/src/connections/github_issues.rs+++ b/crates/screenpipe-connect/src/connections/github_issues.rs@@ -42,6 +42,10 @@ impl Integration for GithubIssues {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {// GitHub's REST API edge rejects requests with a missing or empty// User-Agent before they ever hit auth, returning 403 with body:diff --git a/crates/screenpipe-connect/src/connections/gmail.rs b/crates/screenpipe-connect/src/connections/gmail.rsindex bf90425e7..3cb3c27f4 100644--- a/crates/screenpipe-connect/src/connections/gmail.rs+++ b/crates/screenpipe-connect/src/connections/gmail.rs@@ -57,6 +57,10 @@ impl Integration for Gmail {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://gmail.googleapis.com/gmail/v1",diff --git a/crates/screenpipe-connect/src/connections/google_calendar.rs b/crates/screenpipe-connect/src/connections/google_calendar.rsindex bc2d7c799..46f19ca8f 100644--- a/crates/screenpipe-connect/src/connections/google_calendar.rs+++ b/crates/screenpipe-connect/src/connections/google_calendar.rs@@ -54,6 +54,10 @@ impl Integration for GoogleCalendar {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://www.googleapis.com",diff --git a/crates/screenpipe-connect/src/connections/google_docs.rs b/crates/screenpipe-connect/src/connections/google_docs.rsindex ca08e0e4e..1a023d8df 100644--- a/crates/screenpipe-connect/src/connections/google_docs.rs+++ b/crates/screenpipe-connect/src/connections/google_docs.rs@@ -67,6 +67,10 @@ impl Integration for GoogleDocs {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {// Drive API lives on www.googleapis.com (/drive/v3/...).diff --git a/crates/screenpipe-connect/src/connections/google_sheets.rs b/crates/screenpipe-connect/src/connections/google_sheets.rsindex 3368c6a97..dafecad86 100644--- a/crates/screenpipe-connect/src/connections/google_sheets.rs+++ b/crates/screenpipe-connect/src/connections/google_sheets.rs@@ -65,6 +65,10 @@ impl Integration for GoogleSheets {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://sheets.googleapis.com/v4/spreadsheets",diff --git a/crates/screenpipe-connect/src/connections/microsoft365.rs b/crates/screenpipe-connect/src/connections/microsoft365.rsindex a7a344eee..4e184d1a9 100644--- a/crates/screenpipe-connect/src/connections/microsoft365.rs+++ b/crates/screenpipe-connect/src/connections/microsoft365.rs@@ -96,6 +96,10 @@ impl Integration for Microsoft365 {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://graph.microsoft.com/v1.0",diff --git a/crates/screenpipe-connect/src/connections/mod.rs b/crates/screenpipe-connect/src/connections/mod.rsindex 7c84b5be0..60e1ecb3b 100644--- a/crates/screenpipe-connect/src/connections/mod.rs+++ b/crates/screenpipe-connect/src/connections/mod.rs@@ -198,6 +198,12 @@ pub trait Integration: Send + Sync {&[]}+ /// Whether repeated OAuth connects can create distinct account/workspace+ /// instances instead of overwriting the provider's default token slot.+ fn supports_oauth_instances(&self) -> bool {+ false+ }+/// Background refresh policy. Defaults to "rely on access-token expiry"./// Override when the provider expires the refresh token on inactivity.fn refresh_policy(&self) -> RefreshPolicy {@@ -520,6 +526,7 @@ impl ConnectionManager {def,connected,is_oauth,+ supports_oauth_instances: is_oauth && i.supports_oauth_instances(),});}result@@ -683,6 +690,8 @@ pub struct ConnectionInfo {pub connected: bool,/// True if this integration authenticates via OAuth (no manual fields).pub is_oauth: bool,+ /// True if OAuth reconnects can be stored as separate named instances.+ pub supports_oauth_instances: bool,}type CredentialConnection<'a> = (diff --git a/crates/screenpipe-connect/src/connections/teams.rs b/crates/screenpipe-connect/src/connections/teams.rsindex f3e83af20..19ca29e9a 100644--- a/crates/screenpipe-connect/src/connections/teams.rs+++ b/crates/screenpipe-connect/src/connections/teams.rs@@ -83,6 +83,10 @@ impl Integration for Teams {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://graph.microsoft.com/v1.0",diff --git a/crates/screenpipe-connect/src/connections/vercel.rs b/crates/screenpipe-connect/src/connections/vercel.rsindex 4dafd9c28..e65c594ce 100644--- a/crates/screenpipe-connect/src/connections/vercel.rs+++ b/crates/screenpipe-connect/src/connections/vercel.rs@@ -44,6 +44,10 @@ impl Integration for Vercel {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {static CFG: ProxyConfig = ProxyConfig {base_url: "https://api.vercel.com",diff --git a/crates/screenpipe-connect/src/connections/zendesk.rs b/crates/screenpipe-connect/src/connections/zendesk.rsindex 7829aef28..ce3d1698a 100644--- a/crates/screenpipe-connect/src/connections/zendesk.rs+++ b/crates/screenpipe-connect/src/connections/zendesk.rs@@ -79,6 +79,10 @@ impl Integration for Zendesk {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn proxy_config(&self) -> Option<&'static ProxyConfig> {// base_url's {subdomain} resolves from the OAuth token JSON (stamped at// connect time) for OAuth connections, or from the manual `subdomain`diff --git a/crates/screenpipe-connect/src/connections/zoom.rs b/crates/screenpipe-connect/src/connections/zoom.rsindex 4989cb53a..e122d7b0a 100644--- a/crates/screenpipe-connect/src/connections/zoom.rs+++ b/crates/screenpipe-connect/src/connections/zoom.rs@@ -72,6 +72,10 @@ impl Integration for Zoom {Some(&OAUTH)}+ fn supports_oauth_instances(&self) -> bool {+ true+ }+fn refresh_policy(&self) -> super::RefreshPolicy {// Zoom invalidates refresh tokens after 15h of inactivity (per Zoom// OAuth docs, "refresh token TTL"). Force a proactive refresh well