Connecting to OAuth Apps
Handle the user connection flow for apps like Google, GitHub, Slack
This guide details the programmatic steps required to connect your users (Entities) to external applications that use OAuth 2.0 for authorization (e.g., Google Workspace, GitHub, Slack, Salesforce).
This flow involves redirecting the user to the external service’s login and consent screen in their browser.
Prerequisites:
- An Integration for the OAuth app must be configured in Composio, providing you with an
integration_id
. Ensure it’s set up correctly for OAuth (using Composio’s shared app or your own credentials). - A unique
entity_id
representing the user within your application.
OAuth Connection Flow
The process involves initiating the connection, redirecting the user for authorization, and then waiting for Composio to confirm the connection is active.
Step 1: Initiate the Connection
Use the initiate_connection
(Python) or initiateConnection
(TypeScript) method on the user’s Entity
object. Provide the integration_id
for the OAuth app you configured.
The key output here is the redirectUrl
.
Step 2: Redirect the User
Your application must now direct the user’s browser to the redirectUrl
obtained in Step 1.
- How: This typically involves sending an HTTP 302 Redirect response from your backend, or using
window.location.href = redirectUrl;
in your frontend JavaScript.
The user will see the external service’s login page (if not already logged in) followed by an authorization screen asking them to grant the permissions (scopes) defined in your Composio Integration.
Step 3: Wait for Connection Activation
After the user authorizes the app, the external service redirects back (typically to Composio’s callback URL). Composio exchanges the authorization code for access/refresh tokens and securely stores them, marking the Connection as ACTIVE
.
Your application needs to wait for this confirmation. Use the wait_until_active
(Python) / waitUntilActive
(TypeScript) method on the connection_request
object obtained in Step 1.
Step 4: Use the Connection
Once wait_until_active
completes successfully, the Connection is ready. You can now use the entity_id
or the obtained active_connection.id
to execute actions on behalf of this user for the connected app.