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
haxzie committed
May 15, 2025 at 22:36 UTC
a0176083c1bb1a0a7d50246fff05fc3b25abf7c9
4 files changed
+224
-50
packages/core/src/composio.ts
+5
-4
@@ -54,10 +54,12 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
54
toolkits: Toolkits;
55
triggers: Triggers;
56
toolset: TToolset;
57
+ // auth configs
58
authConfigs: AuthConfigs;
59
+ createAuthConfig: AuthConfigs['create'];
60
// connected accounts
61
connectedAccounts: ConnectedAccounts;
60
- createConnectedAccount: ConnectedAccounts['createConnectedAccount'];
62
+ createConnectedAccount: ConnectedAccounts['create'];
63
64
/**
65
* @param {Object} config Configuration for the Composio SDK.
@@ -105,12 +107,11 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
107
this.toolkits = new Toolkits(this.client);
108
this.triggers = new Triggers(this.client);
109
this.authConfigs = new AuthConfigs(this.client);
110
+ this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
111
112
// Initialize the connected accounts model.
113
this.connectedAccounts = new ConnectedAccounts(this.client);
111
- this.createConnectedAccount = this.connectedAccounts.createConnectedAccount.bind(
112
- this.connectedAccounts
113
- );
114
+ this.createConnectedAccount = this.connectedAccounts.create.bind(this.connectedAccounts);
115
116
/**
117
* Initialize the client telemetry.
packages/core/src/models/AuthConfigs.ts
+88
-15
@@ -7,16 +7,24 @@
7
*/
8
import ComposioClient from '@composio/client';
9
import {
10
- AuthConfigListParams,
11
- AuthConfigListResponse,
12
- AuthConfigCreateParams,
13
- AuthConfigCreateResponse,
10
+ AuthConfigRetrieveResponse as ComposioAuthConfigRetrieveResponse,
11
AuthConfigDeleteResponse,
15
- AuthConfigRetrieveResponse,
16
- AuthConfigUpdateParams,
12
AuthConfigUpdateResponse,
13
AuthConfigUpdateStatusResponse,
14
} from '@composio/client/resources/auth-configs';
15
+import {
16
+ AuthConfigListParams,
17
+ AuthConfigListParamsSchema,
18
+ AuthConfigListResponse,
19
+ AuthConfigListResponseSchema,
20
+ AuthConfigRetrieveResponse,
21
+ AuthConfigRetrieveResponseSchema,
22
+ AuthConfigUpdateParams,
23
+ CreateAuthConfigParams,
24
+ CreateAuthConfigParamsSchema,
25
+ CreateAuthConfigResponse,
26
+ CreateAuthConfigResponseSchema,
27
+} from '../types/authConfigs.types';
28
29
/**
30
* AuthConfigs class
@@ -25,13 +33,35 @@ import {
33
* Auth configs are used to configure authentication providers and settings.
34
*/
35
export class AuthConfigs {
28
- readonly FILE_NAME: string = 'core/models/AuthConfigs.ts';
36
private client: ComposioClient;
37
38
constructor(client: ComposioClient) {
39
this.client = client;
40
}
41
42
+ private parseAuthConfigRetrieveResponse(
43
+ authConfig: ComposioAuthConfigRetrieveResponse
44
+ ): AuthConfigRetrieveResponse {
45
+ return AuthConfigRetrieveResponseSchema.parse({
46
+ id: authConfig.id,
47
+ name: authConfig.name,
48
+ noOfConnections: authConfig.no_of_connections,
49
+ status: authConfig.status,
50
+ toolkit: {
51
+ logo: authConfig.toolkit.logo,
52
+ slug: authConfig.toolkit.slug,
53
+ },
54
+ uuid: authConfig.uuid,
55
+ authScheme: authConfig.auth_scheme,
56
+ credentials: authConfig.credentials,
57
+ expectedInputFields: authConfig.expected_input_fields,
58
+ isComposioManaged: authConfig.is_composio_managed,
59
+ createdBy: authConfig.created_by,
60
+ createdAt: authConfig.created_at,
61
+ lastUpdatedAt: authConfig.last_updated_at,
62
+ });
63
+ }
64
+
65
/**
66
* List all auth configs
67
* @param {AuthConfigListParams} query - Query parameters for filtering auth configs
@@ -39,17 +69,55 @@ export class AuthConfigs {
69
* @returns {Promise<AuthConfigListResponse>} List of auth configs
70
*/
71
async list(query?: AuthConfigListParams): Promise<AuthConfigListResponse> {
42
- return this.client.authConfigs.list(query);
72
+ const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : undefined;
73
+ const result = await this.client.authConfigs.list({
74
+ cursor: parsedQuery?.cursor,
75
+ is_composio_managed: parsedQuery?.isComposioManaged,
76
+ limit: parsedQuery?.limit?.toString(),
77
+ toolkit_slug: parsedQuery?.toolkitSlug,
78
+ });
79
+ return AuthConfigListResponseSchema.parse({
80
+ items: result.items.map(item => this.parseAuthConfigRetrieveResponse(item)),
81
+ nextCursor: result.next_cursor,
82
+ totalPages: result.total_pages,
83
+ });
84
}
85
86
/**
87
* Create a new auth config
47
- * @param {AuthConfigCreateParams} data - Data for creating a new auth config
48
- * @param {RequestOptions} options - Request options
49
- * @returns {Promise<AuthConfigCreateResponse>} Created auth config
88
+ * @param {string} toolkit - Unique identifier of the toolkit
89
+ * @param {CreateAuthConfigParams} options - Options for creating a new auth config
90
+ * @returns {Promise<CreateAuthConfigResponse>} Created auth config
91
+ *
92
+ * @example
93
+ * const authConfig = await authConfigs.create('my-toolkit', {
94
+ * type: AuthConfigTypes.CUSTOM,
95
+ * name: 'My Custom Auth Config',
96
+ * authScheme: AuthSchemeTypes.API_KEY,
97
+ * credentials: {
98
+ * apiKey: '1234567890',
99
+ * },
100
+ * });
101
+ *
102
+ * @link https://docs.composio.dev/reference/auth-configs/create-auth-config
103
*/
51
- async create(data: AuthConfigCreateParams): Promise<AuthConfigCreateResponse> {
52
- return this.client.authConfigs.create(data);
104
+ async create(
105
+ toolkit: string,
106
+ options: CreateAuthConfigParams
107
+ ): Promise<CreateAuthConfigResponse> {
108
+ const parsedOptions = CreateAuthConfigParamsSchema.parse(options);
109
+ const result = await this.client.authConfigs.create({
110
+ toolkit: {
111
+ slug: toolkit,
112
+ },
113
+ auth_config: parsedOptions,
114
+ });
115
+ return CreateAuthConfigResponseSchema.parse({
116
+ id: result.auth_config.id,
117
+ authScheme: result.auth_config.auth_scheme,
118
+ isComposioManaged: result.auth_config.is_composio_managed,
119
+ toolkit: result.toolkit.slug,
120
+ });
121
}
122
123
/**
@@ -59,7 +127,8 @@ export class AuthConfigs {
127
* @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
128
*/
129
async get(nanoid: string): Promise<AuthConfigRetrieveResponse> {
62
- return this.client.authConfigs.retrieve(nanoid);
130
+ const result = await this.client.authConfigs.retrieve(nanoid);
131
+ return this.parseAuthConfigRetrieveResponse(result);
132
}
133
134
/**
@@ -70,7 +139,11 @@ export class AuthConfigs {
139
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
140
*/
141
async update(nanoid: string, data: AuthConfigUpdateParams): Promise<AuthConfigUpdateResponse> {
73
- return this.client.authConfigs.update(nanoid, data);
142
+ return this.client.authConfigs.update(nanoid, {
143
+ auth_config: {
144
+ credentials: data.credentials,
145
+ },
146
+ });
147
}
148
149
/**
packages/core/src/models/ConnectedAccounts.ts
+21
-31
@@ -44,13 +44,28 @@ export class ConnectedAccounts {
44
}
45
46
/**
47
- * Create a new connected account
48
- * @param {ConnectedAccountCreateParams} data - Data for creating a new connected account
49
- * @param {RequestOptions} options - Request options
50
- * @returns {Promise<ConnectedAccountCreateResponse>} Created connected account
47
+ * Compound function to create a new connected account.
48
+ * This function creates a new connected account and returns a connection request.
49
+ * Users can then wait for the connection to be established using the `waitForConnection` method.
50
+ * @param {CreateConnectedAccountParams} data - Data for creating a new connected account
51
+ * @returns {Promise<ConnectionRequest>} Connection request object
52
*/
52
- async create(data: ConnectedAccountCreateParams): Promise<ConnectedAccountCreateResponse> {
53
- return this.client.connectedAccounts.create(data);
53
+ async create(
54
+ userId: string,
55
+ authConfigId: string,
56
+ options?: CreateConnectedAccountOptions
57
+ ): Promise<ConnectionRequest> {
58
+ const response = await this.client.connectedAccounts.create({
59
+ auth_config: {
60
+ id: authConfigId,
61
+ },
62
+ connection: {
63
+ data: options?.data,
64
+ redirect_uri: options?.redirectUrl,
65
+ user_id: userId,
66
+ },
67
+ });
68
+ return new ConnectionRequest(this.client, response.id, response.status);
69
}
70
71
/**
@@ -116,29 +131,4 @@ export class ConnectedAccounts {
131
async disable(nanoid: string): Promise<ConnectedAccountUpdateStatusResponse> {
132
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
133
}
119
-
120
- /**
121
- * Compound function to create a new connected account.
122
- * This function creates a new connected account and returns a connection request.
123
- * Users can then wait for the connection to be established using the `waitForConnection` method.
124
- * @param {CreateConnectedAccountParams} data - Data for creating a new connected account
125
- * @returns {Promise<ConnectionRequest>} Connection request object
126
- */
127
- async createConnectedAccount(
128
- userId: string,
129
- authConfigId: string,
130
- options?: CreateConnectedAccountOptions
131
- ): Promise<ConnectionRequest> {
132
- const response = await this.create({
133
- auth_config: {
134
- id: authConfigId,
135
- },
136
- connection: {
137
- data: options?.data,
138
- redirect_uri: options?.redirectUrl,
139
- user_id: userId,
140
- },
141
- });
142
- return new ConnectionRequest(this.client, response.id, response.status);
143
- }
134
}
packages/core/src/types/authConfigs.types.ts
new
+110
@@ -0,0 +1,110 @@
1
+import { z } from 'zod';
2
+
3
+export const AuthConfigTypes = {
4
+ CUSTOM: 'use_custom_auth',
5
+ COMPOSIO_MANAGED: 'use_composio_managed_auth',
6
+} as const;
7
+export type AuthConfigType = (typeof AuthConfigTypes)[keyof typeof AuthConfigTypes];
8
+
9
+export const AuthSchemeTypes = {
10
+ OAUTH2: 'OAUTH2',
11
+ OAUTH1: 'OAUTH1',
12
+ OAUTH1A: 'OAUTH1A',
13
+ API_KEY: 'API_KEY',
14
+ BASIC: 'BASIC',
15
+ BILLCOM_AUTH: 'BILLCOM_AUTH',
16
+ BEARER_TOKEN: 'BEARER_TOKEN',
17
+ GOOGLE_SERVICE_ACCOUNT: 'GOOGLE_SERVICE_ACCOUNT',
18
+ NO_AUTH: 'NO_AUTH',
19
+ BASIC_WITH_JWT: 'BASIC_WITH_JWT',
20
+ COMPOSIO_LINK: 'COMPOSIO_LINK',
21
+ CALCOM_AUTH: 'CALCOM_AUTH',
22
+ SNOWFLAKE: 'SNOWFLAKE',
23
+} as const;
24
+export type AuthSchemeType = (typeof AuthSchemeTypes)[keyof typeof AuthSchemeTypes];
25
+
26
+export const AuthSchemeEnum = z.enum([
27
+ 'OAUTH2',
28
+ 'OAUTH1',
29
+ 'OAUTH1A',
30
+ 'API_KEY',
31
+ 'BASIC',
32
+ 'BILLCOM_AUTH',
33
+ 'BEARER_TOKEN',
34
+ 'GOOGLE_SERVICE_ACCOUNT',
35
+ 'NO_AUTH',
36
+ 'BASIC_WITH_JWT',
37
+ 'COMPOSIO_LINK',
38
+ 'CALCOM_AUTH',
39
+ 'SNOWFLAKE',
40
+]);
41
+export const CreateCustomAuthConfigParamsSchema = z.object({
42
+ type: z.literal('use_custom_auth'),
43
+ name: z.string().optional(),
44
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
45
+ authScheme: AuthSchemeEnum,
46
+});
47
+
48
+export const CreateComposioManagedAuthConfigParamsSchema = z.object({
49
+ type: z.literal('use_composio_managed_auth'),
50
+ name: z.string().optional(),
51
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
52
+});
53
+
54
+/**
55
+ * Discriminated union of all possible auth config types.
56
+ */
57
+export const CreateAuthConfigParamsSchema = z.discriminatedUnion('type', [
58
+ CreateCustomAuthConfigParamsSchema,
59
+ CreateComposioManagedAuthConfigParamsSchema,
60
+]);
61
+
62
+export type CreateAuthConfigParams = z.infer<typeof CreateAuthConfigParamsSchema>;
63
+
64
+export const CreateAuthConfigResponseSchema = z.object({
65
+ id: z.string(),
66
+ authScheme: z.string(),
67
+ isComposioManaged: z.boolean(),
68
+ toolkit: z.string(),
69
+});
70
+export type CreateAuthConfigResponse = z.infer<typeof CreateAuthConfigResponseSchema>;
71
+
72
+export const AuthConfigRetrieveResponseSchema = z.object({
73
+ id: z.string(),
74
+ name: z.string(),
75
+ toolkit: z.object({
76
+ logo: z.string(),
77
+ slug: z.string(),
78
+ }),
79
+ noOfConnections: z.number(),
80
+ status: z.enum(['ENABLED', 'DISABLED']),
81
+ uuid: z.string(),
82
+ authScheme: AuthSchemeEnum.optional(),
83
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
84
+ expectedInputFields: z.array(z.unknown()).optional(),
85
+ isComposioManaged: z.boolean().optional(),
86
+ createdBy: z.string().optional(),
87
+ createdAt: z.string().optional(),
88
+ lastUpdatedAt: z.string().optional(),
89
+});
90
+export type AuthConfigRetrieveResponse = z.infer<typeof AuthConfigRetrieveResponseSchema>;
91
+
92
+export const AuthConfigListParamsSchema = z.object({
93
+ cursor: z.string().optional(),
94
+ isComposioManaged: z.boolean().optional(),
95
+ limit: z.number().optional(),
96
+ toolkitSlug: z.string().optional(),
97
+});
98
+export type AuthConfigListParams = z.infer<typeof AuthConfigListParamsSchema>;
99
+
100
+export const AuthConfigListResponseSchema = z.object({
101
+ items: z.array(AuthConfigRetrieveResponseSchema),
102
+ nextCursor: z.string().optional(),
103
+ totalPages: z.number(),
104
+});
105
+export type AuthConfigListResponse = z.infer<typeof AuthConfigListResponseSchema>;
106
+
107
+export const AuthConfigUpdateParamsSchema = z.object({
108
+ credentials: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
109
+});
110
+export type AuthConfigUpdateParams = z.infer<typeof AuthConfigUpdateParamsSchema>;