Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Update auth configs and create connected accounts

haxziea0176083c1bb
diff --git a/packages/core/src/composio.ts b/packages/core/src/composio.ts
index e9eb8820f..348c37a61 100644
--- a/packages/core/src/composio.ts
+++ b/packages/core/src/composio.ts
@@ -54,10 +54,12 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
toolkits: Toolkits;
triggers: Triggers;
toolset: TToolset;
+ // auth configs
authConfigs: AuthConfigs;
+ createAuthConfig: AuthConfigs['create'];
// connected accounts
connectedAccounts: ConnectedAccounts;
- createConnectedAccount: ConnectedAccounts['createConnectedAccount'];
+ createConnectedAccount: ConnectedAccounts['create'];
/**
* @param {Object} config Configuration for the Composio SDK.
@@ -105,12 +107,11 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
this.toolkits = new Toolkits(this.client);
this.triggers = new Triggers(this.client);
this.authConfigs = new AuthConfigs(this.client);
+ this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
// Initialize the connected accounts model.
this.connectedAccounts = new ConnectedAccounts(this.client);
- this.createConnectedAccount = this.connectedAccounts.createConnectedAccount.bind(
- this.connectedAccounts
- );
+ this.createConnectedAccount = this.connectedAccounts.create.bind(this.connectedAccounts);
/**
* Initialize the client telemetry.
diff --git a/packages/core/src/models/AuthConfigs.ts b/packages/core/src/models/AuthConfigs.ts
index 69935ed1c..36f792990 100644
--- a/packages/core/src/models/AuthConfigs.ts
+++ b/packages/core/src/models/AuthConfigs.ts
@@ -7,16 +7,24 @@
*/
import ComposioClient from '@composio/client';
import {
- AuthConfigListParams,
- AuthConfigListResponse,
- AuthConfigCreateParams,
- AuthConfigCreateResponse,
+ AuthConfigRetrieveResponse as ComposioAuthConfigRetrieveResponse,
AuthConfigDeleteResponse,
- AuthConfigRetrieveResponse,
- AuthConfigUpdateParams,
AuthConfigUpdateResponse,
AuthConfigUpdateStatusResponse,
} from '@composio/client/resources/auth-configs';
+import {
+ AuthConfigListParams,
+ AuthConfigListParamsSchema,
+ AuthConfigListResponse,
+ AuthConfigListResponseSchema,
+ AuthConfigRetrieveResponse,
+ AuthConfigRetrieveResponseSchema,
+ AuthConfigUpdateParams,
+ CreateAuthConfigParams,
+ CreateAuthConfigParamsSchema,
+ CreateAuthConfigResponse,
+ CreateAuthConfigResponseSchema,
+} from '../types/authConfigs.types';
/**
* AuthConfigs class
@@ -25,13 +33,35 @@ import {
* Auth configs are used to configure authentication providers and settings.
*/
export class AuthConfigs {
- readonly FILE_NAME: string = 'core/models/AuthConfigs.ts';
private client: ComposioClient;
constructor(client: ComposioClient) {
this.client = client;
}
+ private parseAuthConfigRetrieveResponse(
+ authConfig: ComposioAuthConfigRetrieveResponse
+ ): AuthConfigRetrieveResponse {
+ return AuthConfigRetrieveResponseSchema.parse({
+ id: authConfig.id,
+ name: authConfig.name,
+ noOfConnections: authConfig.no_of_connections,
+ status: authConfig.status,
+ toolkit: {
+ logo: authConfig.toolkit.logo,
+ slug: authConfig.toolkit.slug,
+ },
+ uuid: authConfig.uuid,
+ authScheme: authConfig.auth_scheme,
+ credentials: authConfig.credentials,
+ expectedInputFields: authConfig.expected_input_fields,
+ isComposioManaged: authConfig.is_composio_managed,
+ createdBy: authConfig.created_by,
+ createdAt: authConfig.created_at,
+ lastUpdatedAt: authConfig.last_updated_at,
+ });
+ }
+
/**
* List all auth configs
* @param {AuthConfigListParams} query - Query parameters for filtering auth configs
@@ -39,17 +69,55 @@ export class AuthConfigs {
* @returns {Promise<AuthConfigListResponse>} List of auth configs
*/
async list(query?: AuthConfigListParams): Promise<AuthConfigListResponse> {
- return this.client.authConfigs.list(query);
+ const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : undefined;
+ const result = await this.client.authConfigs.list({
+ cursor: parsedQuery?.cursor,
+ is_composio_managed: parsedQuery?.isComposioManaged,
+ limit: parsedQuery?.limit?.toString(),
+ toolkit_slug: parsedQuery?.toolkitSlug,
+ });
+ return AuthConfigListResponseSchema.parse({
+ items: result.items.map(item => this.parseAuthConfigRetrieveResponse(item)),
+ nextCursor: result.next_cursor,
+ totalPages: result.total_pages,
+ });
}
/**
* Create a new auth config
- * @param {AuthConfigCreateParams} data - Data for creating a new auth config
- * @param {RequestOptions} options - Request options
- * @returns {Promise<AuthConfigCreateResponse>} Created auth config
+ * @param {string} toolkit - Unique identifier of the toolkit
+ * @param {CreateAuthConfigParams} options - Options for creating a new auth config
+ * @returns {Promise<CreateAuthConfigResponse>} Created auth config
+ *
+ * @example
+ * const authConfig = await authConfigs.create('my-toolkit', {
+ * type: AuthConfigTypes.CUSTOM,
+ * name: 'My Custom Auth Config',
+ * authScheme: AuthSchemeTypes.API_KEY,
+ * credentials: {
+ * apiKey: '1234567890',
+ * },
+ * });
+ *
+ * @link https://docs.composio.dev/reference/auth-configs/create-auth-config
*/
- async create(data: AuthConfigCreateParams): Promise<AuthConfigCreateResponse> {
- return this.client.authConfigs.create(data);
+ async create(
+ toolkit: string,
+ options: CreateAuthConfigParams
+ ): Promise<CreateAuthConfigResponse> {
+ const parsedOptions = CreateAuthConfigParamsSchema.parse(options);
+ const result = await this.client.authConfigs.create({
+ toolkit: {
+ slug: toolkit,
+ },
+ auth_config: parsedOptions,
+ });
+ return CreateAuthConfigResponseSchema.parse({
+ id: result.auth_config.id,
+ authScheme: result.auth_config.auth_scheme,
+ isComposioManaged: result.auth_config.is_composio_managed,
+ toolkit: result.toolkit.slug,
+ });
}
/**
@@ -59,7 +127,8 @@ export class AuthConfigs {
* @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
*/
async get(nanoid: string): Promise<AuthConfigRetrieveResponse> {
- return this.client.authConfigs.retrieve(nanoid);
+ const result = await this.client.authConfigs.retrieve(nanoid);
+ return this.parseAuthConfigRetrieveResponse(result);
}
/**
@@ -70,7 +139,11 @@ export class AuthConfigs {
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
*/
async update(nanoid: string, data: AuthConfigUpdateParams): Promise<AuthConfigUpdateResponse> {
- return this.client.authConfigs.update(nanoid, data);
+ return this.client.authConfigs.update(nanoid, {
+ auth_config: {
+ credentials: data.credentials,
+ },
+ });
}
/**
diff --git a/packages/core/src/models/ConnectedAccounts.ts b/packages/core/src/models/ConnectedAccounts.ts
index 8418eb069..da35159c6 100644
--- a/packages/core/src/models/ConnectedAccounts.ts
+++ b/packages/core/src/models/ConnectedAccounts.ts
@@ -44,13 +44,28 @@ export class ConnectedAccounts {
}
/**
- * Create a new connected account
- * @param {ConnectedAccountCreateParams} data - Data for creating a new connected account
- * @param {RequestOptions} options - Request options
- * @returns {Promise<ConnectedAccountCreateResponse>} Created connected account
+ * Compound function to create a new connected account.
+ * This function creates a new connected account and returns a connection request.
+ * Users can then wait for the connection to be established using the `waitForConnection` method.
+ * @param {CreateConnectedAccountParams} data - Data for creating a new connected account
+ * @returns {Promise<ConnectionRequest>} Connection request object
*/
- async create(data: ConnectedAccountCreateParams): Promise<ConnectedAccountCreateResponse> {
- return this.client.connectedAccounts.create(data);
+ async create(
+ userId: string,
+ authConfigId: string,
+ options?: CreateConnectedAccountOptions
+ ): Promise<ConnectionRequest> {
+ const response = await this.client.connectedAccounts.create({
+ auth_config: {
+ id: authConfigId,
+ },
+ connection: {
+ data: options?.data,
+ redirect_uri: options?.redirectUrl,
+ user_id: userId,
+ },
+ });
+ return new ConnectionRequest(this.client, response.id, response.status);
}
/**
@@ -116,29 +131,4 @@ export class ConnectedAccounts {
async disable(nanoid: string): Promise<ConnectedAccountUpdateStatusResponse> {
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
}
-
- /**
- * Compound function to create a new connected account.
- * This function creates a new connected account and returns a connection request.
- * Users can then wait for the connection to be established using the `waitForConnection` method.
- * @param {CreateConnectedAccountParams} data - Data for creating a new connected account
- * @returns {Promise<ConnectionRequest>} Connection request object
- */
- async createConnectedAccount(
- userId: string,
- authConfigId: string,
- options?: CreateConnectedAccountOptions
- ): Promise<ConnectionRequest> {
- const response = await this.create({
- auth_config: {
- id: authConfigId,
- },
- connection: {
- data: options?.data,
- redirect_uri: options?.redirectUrl,
- user_id: userId,
- },
- });
- return new ConnectionRequest(this.client, response.id, response.status);
- }
}
diff --git a/packages/core/src/types/authConfigs.types.ts b/packages/core/src/types/authConfigs.types.ts
new file mode 100644
index 000000000..45e483de6
--- /dev/null
+++ b/packages/core/src/types/authConfigs.types.ts
@@ -0,0 +1,110 @@
+import { z } from 'zod';
+
+export const AuthConfigTypes = {
+ CUSTOM: 'use_custom_auth',
+ COMPOSIO_MANAGED: 'use_composio_managed_auth',
+} as const;
+export type AuthConfigType = (typeof AuthConfigTypes)[keyof typeof AuthConfigTypes];
+
+export const AuthSchemeTypes = {
+ OAUTH2: 'OAUTH2',
+ OAUTH1: 'OAUTH1',
+ OAUTH1A: 'OAUTH1A',
+ API_KEY: 'API_KEY',
+ BASIC: 'BASIC',
+ BILLCOM_AUTH: 'BILLCOM_AUTH',
+ BEARER_TOKEN: 'BEARER_TOKEN',
+ GOOGLE_SERVICE_ACCOUNT: 'GOOGLE_SERVICE_ACCOUNT',
+ NO_AUTH: 'NO_AUTH',
+ BASIC_WITH_JWT: 'BASIC_WITH_JWT',
+ COMPOSIO_LINK: 'COMPOSIO_LINK',
+ CALCOM_AUTH: 'CALCOM_AUTH',
+ SNOWFLAKE: 'SNOWFLAKE',
+} as const;
+export type AuthSchemeType = (typeof AuthSchemeTypes)[keyof typeof AuthSchemeTypes];
+
+export const AuthSchemeEnum = z.enum([
+ 'OAUTH2',
+ 'OAUTH1',
+ 'OAUTH1A',
+ 'API_KEY',
+ 'BASIC',
+ 'BILLCOM_AUTH',
+ 'BEARER_TOKEN',
+ 'GOOGLE_SERVICE_ACCOUNT',
+ 'NO_AUTH',
+ 'BASIC_WITH_JWT',
+ 'COMPOSIO_LINK',
+ 'CALCOM_AUTH',
+ 'SNOWFLAKE',
+]);
+export const CreateCustomAuthConfigParamsSchema = z.object({
+ type: z.literal('use_custom_auth'),
+ name: z.string().optional(),
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
+ authScheme: AuthSchemeEnum,
+});
+
+export const CreateComposioManagedAuthConfigParamsSchema = z.object({
+ type: z.literal('use_composio_managed_auth'),
+ name: z.string().optional(),
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
+});
+
+/**
+ * Discriminated union of all possible auth config types.
+ */
+export const CreateAuthConfigParamsSchema = z.discriminatedUnion('type', [
+ CreateCustomAuthConfigParamsSchema,
+ CreateComposioManagedAuthConfigParamsSchema,
+]);
+
+export type CreateAuthConfigParams = z.infer<typeof CreateAuthConfigParamsSchema>;
+
+export const CreateAuthConfigResponseSchema = z.object({
+ id: z.string(),
+ authScheme: z.string(),
+ isComposioManaged: z.boolean(),
+ toolkit: z.string(),
+});
+export type CreateAuthConfigResponse = z.infer<typeof CreateAuthConfigResponseSchema>;
+
+export const AuthConfigRetrieveResponseSchema = z.object({
+ id: z.string(),
+ name: z.string(),
+ toolkit: z.object({
+ logo: z.string(),
+ slug: z.string(),
+ }),
+ noOfConnections: z.number(),
+ status: z.enum(['ENABLED', 'DISABLED']),
+ uuid: z.string(),
+ authScheme: AuthSchemeEnum.optional(),
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
+ expectedInputFields: z.array(z.unknown()).optional(),
+ isComposioManaged: z.boolean().optional(),
+ createdBy: z.string().optional(),
+ createdAt: z.string().optional(),
+ lastUpdatedAt: z.string().optional(),
+});
+export type AuthConfigRetrieveResponse = z.infer<typeof AuthConfigRetrieveResponseSchema>;
+
+export const AuthConfigListParamsSchema = z.object({
+ cursor: z.string().optional(),
+ isComposioManaged: z.boolean().optional(),
+ limit: z.number().optional(),
+ toolkitSlug: z.string().optional(),
+});
+export type AuthConfigListParams = z.infer<typeof AuthConfigListParamsSchema>;
+
+export const AuthConfigListResponseSchema = z.object({
+ items: z.array(AuthConfigRetrieveResponseSchema),
+ nextCursor: z.string().optional(),
+ totalPages: z.number(),
+});
+export type AuthConfigListResponse = z.infer<typeof AuthConfigListResponseSchema>;
+
+export const AuthConfigUpdateParamsSchema = z.object({
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
+});
+export type AuthConfigUpdateParams = z.infer<typeof AuthConfigUpdateParamsSchema>;