Third-Party App Integrations
This document details how AngelCX integrates with third-party applications through OAuth2 authentication and manages these integrations across different services.
Integration Flow Overview
Database Schema
For a detailed description of the third_party_oauth table and other integration-related database tables, see the Database Overview documentation.
Integration Process
1. Available Apps Discovery
- Admin Dashboard queries the database for available integrations:
sql SELECT * FROM third_party_app WHERE is_coming_soon = false; - The UI displays each app with its icon, name, and description
- Apps marked as
is_coming_soon = trueare shown with a "Coming Soon" badge
2. Connection Flow
When a user initiates a connection:
-
Initiate OAuth
- Admin Dashboard calls Admin API endpoint (e.g.,
/api/third-party-apps/{slug}/authorize) - Admin API generates state token and constructs authorization URL
- Returns URL to Admin Dashboard
- Admin Dashboard calls Admin API endpoint (e.g.,
-
Authorization
- User is redirected to third-party service's authorization page
- User grants necessary permissions
- Service redirects back to Admin Dashboard with temporary code
-
Token Exchange
- Admin Dashboard sends code to Admin API
- Admin API exchanges code for access and refresh tokens
- Tokens are stored in
third_party_oauthtable:
sql INSERT INTO third_party_oauth ( access_token, refresh_token, expiry, third_party_app_id, agent_id, additional_data ) VALUES (...);
3. Usage in Services
AI Engine Integration
The AI Engine uses these integrations to provide real-time capabilities to AI agents:
-
Token Retrieval
-
API Calls
- AI Engine uses tokens to make authenticated requests to third-party services
- Responses are processed and used in agent conversations
Post-Session Processing
The Post-Session service handles automated tasks after conversations end:
-
Task Execution
- Service checks for relevant integrations
- Retrieves OAuth tokens
- Executes configured actions (e.g., creating HubSpot contacts)
-
Error Handling
- Failed tasks are retried with exponential backoff
- Token refresh is handled automatically when needed
Security Considerations
-
Token Storage
- Access and refresh tokens are encrypted at rest
- Tokens are never logged or exposed in error messages
-
Token Refresh
- Automatic refresh of expired access tokens
- Refresh tokens are rotated when possible
- Failed refreshes trigger admin notifications
-
Access Control
- OAuth tokens are scoped to specific agents
- Regular audit of token usage and permissions
Token Encryption Implementation Plan
The current implementation will be enhanced with stronger encryption for OAuth tokens using Python's cryptography library. For detailed technical specifications and implementation timeline, see our Token Security Enhancement Plan.
Planned Improvements
-
Encryption at Rest
- Implement Fernet (symmetric encryption) for token storage
- Use a separate key management service (Secret Manager) for encryption keys
- Rotate encryption keys periodically
-
Database Changes
- Modify
third_party_oauthtable to store encrypted tokens - Add key version tracking for rotation management
- Implement automatic re-encryption during key rotation
- Modify
-
Security Measures
- Encryption keys stored separately from data
- Regular key rotation (every 30 days)
-
Decryption During Usage
- When AI Tools or Post-Session services need to access tokens, they retrieve encrypted tokens from the database
- Tokens are decrypted in-memory using the current encryption key before making API calls
- Decrypted tokens are never persisted or logged