#how can I initiate connection

1 messages · Page 1 of 1 (latest)

rustic grove
#

how can I initiate a new connection in composio? i want to use gmail

opal hollowBOT
#

To initiate a new connection to Gmail using Composio, you need to follow these steps:

  1. Create an Auth Config for Gmail
    You need a Gmail OAuth client ID and client secret from your Google OAuth Console. Use these credentials to create an authentication config in Composio. This can be done via the dashboard or programmatically. Here’s an example in TypeScript:

    import { Composio } from '@composio/core';
    import { OpenAIProvider } from '@composio/openai';
    
    export async function createAuthConfig(composioClient: Composio<OpenAIProvider>) {
        const clientId = process.env.GMAIL_CLIENT_ID;
        const clientSecret = process.env.GMAIL_CLIENT_SECRET;
        if (!clientId || !clientSecret) {
            throw new Error("GMAIL_CLIENT_ID and GMAIL_CLIENT_SECRET must be set");
        }
    
        return composioClient.authConfigs.create(
            "GMAIL",
            {
                "name": "default_gmail_auth_config",
                "type": "use_custom_auth",
                "authScheme": "OAUTH2",
                "credentials": {
                    "clientId": clientId,
                    "clientSecret": clientSecret,
                },
            },
        );
    }
    

    Ideally, you should check for an existing auth config before creating a new one.
    Basic Hono Server: Authenticating users

  2. Initiate the Connection
    Once you have the auth config, initiate a connection for your user. This will generate a redirect URL for the OAuth flow: