Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/composio/connectors/__tests__/getConnectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@ describe("getConnectors", () => {
expect(result[0].name).toBe("TikTok");
});

it("should pass authConfigs when custom OAuth env vars are set", async () => {
const origTiktok = process.env.COMPOSIO_TIKTOK_AUTH_CONFIG_ID;
const origInstagram = process.env.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID;

try {
process.env.COMPOSIO_TIKTOK_AUTH_CONFIG_ID = "ac_tiktok_123";
process.env.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID = "ac_instagram_456";

mockToolkits.mockResolvedValue({ items: [] });

await getConnectors("account-123");

expect(mockComposio.create).toHaveBeenCalledWith("account-123", {
toolkits: ["googlesheets", "googledrive", "googledocs", "tiktok", "instagram"],
authConfigs: {
tiktok: "ac_tiktok_123",
instagram: "ac_instagram_456",
},
});
} finally {
if (origTiktok === undefined) delete process.env.COMPOSIO_TIKTOK_AUTH_CONFIG_ID;
else process.env.COMPOSIO_TIKTOK_AUTH_CONFIG_ID = origTiktok;
if (origInstagram === undefined) delete process.env.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID;
else process.env.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID = origInstagram;
}
});

it("should handle inactive connections", async () => {
mockToolkits.mockResolvedValue({
items: [
Expand Down
15 changes: 15 additions & 0 deletions lib/composio/connectors/buildAuthConfigs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Build auth configs from environment variables.
* Must match the configs used during authorization so Composio
* can find connections created with custom OAuth credentials.
*/
export function buildAuthConfigs(): Record<string, string> | undefined {
const configs: Record<string, string> = {};
if (process.env.COMPOSIO_TIKTOK_AUTH_CONFIG_ID) {
configs.tiktok = process.env.COMPOSIO_TIKTOK_AUTH_CONFIG_ID;
}
if (process.env.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID) {
configs.instagram = process.env.COMPOSIO_INSTAGRAM_AUTH_CONFIG_ID;
}
return Object.keys(configs).length > 0 ? configs : undefined;
}
3 changes: 3 additions & 0 deletions lib/composio/connectors/getConnectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getComposioClient } from "../client";
import { buildAuthConfigs } from "./buildAuthConfigs";

/**
* Connector info returned by Composio.
Expand Down Expand Up @@ -44,8 +45,10 @@ export async function getConnectors(
const { displayNames = {} } = options;
const composio = await getComposioClient();

const authConfigs = buildAuthConfigs();
const session = await composio.create(accountId, {
toolkits: SUPPORTED_TOOLKITS,
...(authConfigs && { authConfigs }),
});
const toolkits = await session.toolkits();

Expand Down
Loading