Connecting Apps
Purpose and Scope
This page documents the OAuth connection flow and webhook integration system for connecting external applications (Composio apps) to user workspaces. It covers the two-phase connection process (Add to Workspace → Connect/OAuth), connection state management, and the technical implementation of OAuth callback handling.
For information about browsing and discovering available apps, see Composio Integration. For details on tool execution and action routing, see Tool Router & Execution.
OAuth Connection Architecture
The app connection system implements a two-phase approach: Add to Workspace (workspace registration) and Connect (OAuth authorization). This separation allows users to stage apps before initiating OAuth flows, preventing abandoned OAuth attempts from cluttering the workspace.
Connection Flow Overview
Sources:
Connection Status Lifecycle
Each app connection progresses through distinct states tracked in the entity_connections table. The status field determines UI visibility and connection readiness.
State Transition Diagram
Status Definitions:
added
App registered in workspace but not connected
"Added" badge
Connect (initiate OAuth)
pending
OAuth flow initiated but not completed
"Pending" badge
Refresh status, Cancel
active
OAuth completed, connection ready
"Connected" badge, green indicator
Disconnect, Configure actions
Sources:
orchestrator/core/composio/entity_manager.py (not shown but referenced)
Add to Workspace Flow
The Add to Workspace operation registers an app in the user's workspace without requiring OAuth. This creates a workspace-scoped connection record with status='added', making the app visible in the Applications tab.
Implementation
Key Code Locations:
The add_connection() method creates a new database record:
The endpoint handles duplicate detection:
orchestrator/api/tools.py:475-509
Sources:
OAuth Connection Initiation
After adding an app to the workspace, users click Connect to initiate OAuth. This flow redirects to Composio's OAuth provider and updates the connection status to pending.
OAuth Initiation Flow
Connection Initiation Code:
orchestrator/api/tools.py:370-394
Sources:
orchestrator/core/composio/client.py (referenced but not shown)
OAuth Callback Handling
After OAuth authorization, Composio redirects to the callback URL with an authorization code. The backend exchanges this code for access tokens and updates the connection status to active.
Callback Processing
The callback endpoint is typically defined in orchestrator/api/composio.py (not shown in provided files, but referenced in the flow). The process:
Receive callback with
codeandstateparametersVerify state matches workspace/entity context
Exchange code for tokens via Composio API
Update status in database from
pending→activeStore connection_id from Composio response
Redirect user back to Tools page
Connection Status Update:
orchestrator/api/tools.py:666-671
Sources:
Webhook Integration
Many Composio apps support webhook triggers for real-time event notifications. Webhooks are configured automatically during connection and stored in the composio_apps_cache.app_metadata field.
Webhook Trigger Schema
Triggers are synced during metadata sync and exposed via the /api/tools/{app_name}/triggers endpoint:
orchestrator/api/tools.py:312-330
Trigger Metadata Structure
Triggers are stored in the app_metadata JSONB column:
Sources:
Managing Connected Apps
Once connected, apps appear in the /api/tools/connected endpoint with status='active'. Users can view connection details, configure enabled actions, and disconnect apps.
Connected Apps Query
Connected Apps Response Structure:
orchestrator/api/tools.py:201-259
Disconnecting Apps
Apps can be removed via:
orchestrator/api/tools.py:566-595
Sources:
Connection Refresh and Sync
Pending connections can be manually refreshed to check if OAuth was completed. This avoids automatic API calls on every page load (performance optimization).
Manual Refresh Flow
Refresh Implementation:
orchestrator/api/tools.py:622-686
Sources:
Frontend Integration
The marketplace tools tab implements the Add to Workspace UI with real-time status indicators.
Add to Workspace Button Logic
Status Indicator Code:
frontend/components/marketplace/marketplace-tools-tab.tsx:430-448
Add to Workspace Handler:
frontend/components/marketplace/marketplace-tools-tab.tsx:250-303
Sources:
Summary
The app connection system implements a robust two-phase flow:
Add to Workspace - Registers app in workspace with
status='added'Connect - Initiates OAuth, transitions to
pending→active
Key technical components:
EntityManagermanages workspace-scoped connection recordsComposioClienthandles OAuth initiation and token exchangeConnection status lifecycle ensures clean state transitions
Manual refresh prevents performance issues from automatic API polling
This architecture prevents abandoned OAuth attempts from creating orphaned records while providing clear user feedback at each stage of the connection process.
Last updated

