Connecting Apps

chevron-rightRelevant source fileshashtag

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

spinner

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

spinner

Status Definitions:

Status
Meaning
UI Representation
Actions Available

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:


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

spinner

Key Code Locations:

The add_connection() method creates a new database record:

orchestrator/api/tools.py:514

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

spinner

Connection Initiation Code:

orchestrator/api/tools.py:370-394

Sources:


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:

  1. Receive callback with code and state parameters

  2. Verify state matches workspace/entity context

  3. Exchange code for tokens via Composio API

  4. Update status in database from pendingactive

  5. Store connection_id from Composio response

  6. 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

spinner

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

spinner

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

spinner

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:

  1. Add to Workspace - Registers app in workspace with status='added'

  2. Connect - Initiates OAuth, transitions to pendingactive

Key technical components:

  • EntityManager manages workspace-scoped connection records

  • ComposioClient handles OAuth initiation and token exchange

  • Connection 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