Skip to main content

Overview

Authentication in Composio allows your users to securely connect their accounts from external services like GitHub, Gmail, Slack, and more. This guide covers different authentication methods, connected account management, and best practices.

Authentication Concepts

Key Components

  • Auth Config: Configuration defining how users authenticate with a service (OAuth2, API Key, etc.)
  • Connected Account: A user’s authenticated connection to a service
  • Connection Request: The process of establishing a new connected account
  • Toolkit: A collection of tools for a specific service (e.g., GitHub toolkit)

Authentication Schemes

Composio supports multiple authentication schemes:
  • OAuth2: Standard OAuth 2.0 flow (most common)
  • OAuth1: OAuth 1.0a for legacy services
  • API Key: Simple API key-based authentication
  • Bearer Token: Token-based authentication
  • Basic Auth: Username and password authentication
  • No Auth: Public APIs that don’t require authentication
  • Service Account: Google Service Accounts and similar
  • Custom: Custom authentication schemes

Creating Connected Accounts

Direct Authentication (Advanced)

For advanced use cases where you already have user credentials, you can create connected accounts directly:

OAuth2 Authentication

API Key Authentication

Basic Authentication

Direct authentication bypasses Composio’s managed OAuth flow. Use the link() method for OAuth services whenever possible to leverage automatic token refresh and better security.

Managing Connected Accounts

Listing Connected Accounts

Getting a Specific Account

Refreshing Credentials

Enabling and Disabling Accounts

Deleting Connected Accounts

Deleting a connected account is permanent and cannot be undone. All associated tokens will be revoked.

Multiple Connected Accounts

By default, Composio prevents users from having multiple connected accounts for the same auth config:
To allow multiple accounts, use the allowMultiple option:

Authentication Error Handling

Connection Request States

Connection requests go through several states:
  • INITIATED: Connection request created, waiting for user action
  • ACTIVE: User completed authentication successfully
  • FAILED: Authentication failed
  • EXPIRED: Connection link expired before completion
  • DELETED: Connection request was cancelled

Working with Auth Configs

Listing Auth Configs

Getting Auth Config Details

Creating Custom Auth Configs

Best Practices

Use Connection Links

Prefer the link() method over direct authentication for OAuth services to ensure proper token management.

Handle Timeouts

Set appropriate timeouts for waitForConnection() based on your UX expectations.

Refresh Tokens

Implement token refresh logic for long-running applications to maintain valid credentials.

Manage State

Store connected account IDs in your database to track user connections.

Frontend Integration Example

Here’s a complete example of integrating authentication in a React application:

Next Steps

Tool Execution

Learn how to execute tools with authenticated accounts

Custom Tools

Create custom tools that use connected accounts

Error Handling

Handle authentication errors gracefully

Environment Variables

Configure authentication settings via environment variables