Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 23, 01:45 UTC
Update docs to show org based access
haxzie committed
May 23, 2025 at 11:58 UTC
a2b8cca45664020590b54baeb7903c8d1cdb778b
1 file changed
+114
docs/core-concepts.md
+114
@@ -71,6 +71,120 @@ const userId = user.externalId; // e.g., "auth0|507f1f77bcf86cd799439011"
71
const userId = user.email; // e.g., "user@example.com"
72
```
73
74
+### Organization-Based Applications
75
+
76
+For **multi-user applications** where users are part of an organization and apps are connected at the **organization level** (not individual user level), use the **organization ID** as the `userId`:
77
+
78
+#### When to Use Organization IDs
79
+
80
+- **Team/Organization tools**: Apps like Slack, Microsoft Teams, or project management tools where the entire organization shares connections
81
+- **Enterprise applications**: Where IT administrators connect apps for the whole organization
82
+- **Shared resources**: When multiple users need access to the same connected accounts (shared Gmail account, company GitHub org, etc.)
83
+- **Role-based access**: Where permissions are managed at the organization level
84
+
85
+#### ✅ **Recommended: Organization ID Pattern**
86
+
87
+```typescript
88
+// Use the organization/team/workspace ID
89
+const userId = organization.id; // e.g., "org_550e8400-e29b-41d4-a716-446655440000"
90
+// or
91
+const userId = `org_${organization.slug}`; // e.g., "org_acme-corp"
92
+
93
+// All users in the organization share the same connected accounts
94
+const tools = await composio.tools.get(userId, {
95
+ toolkits: ['slack', 'github'],
96
+});
97
+
98
+// Execute tools in the organization context
99
+const result = await composio.tools.execute('SLACK_SEND_MESSAGE', {
100
+ userId: userId, // organization ID
101
+ arguments: {
102
+ channel: '#general',
103
+ text: 'Hello from the team!',
104
+ },
105
+});
106
+```
107
+
108
+#### Example: Organization-Based Application
109
+
110
+```typescript
111
+import { Composio } from '@composio/core';
112
+
113
+const composio = new Composio({
114
+ apiKey: process.env.COMPOSIO_API_KEY,
115
+});
116
+
117
+// 1. Admin connects Slack for the entire organization
118
+async function connectOrganizationToSlack(organizationId: string, adminUserId: string) {
119
+ // Use organization ID as userId in Composio
120
+ const connectionRequest = await composio.toolkits.authorize(organizationId, 'slack');
121
+
122
+ // Store the connection request for the admin to complete
123
+ await storeConnectionRequest(organizationId, adminUserId, connectionRequest);
124
+
125
+ return connectionRequest.redirectUrl;
126
+}
127
+
128
+// 2. Any user in the organization can use the connected tools
129
+async function sendSlackMessage(organizationId: string, channel: string, message: string) {
130
+ return await composio.tools.execute('SLACK_SEND_MESSAGE', {
131
+ userId: organizationId, // organization ID, not individual user ID
132
+ arguments: {
133
+ channel: channel,
134
+ text: message,
135
+ },
136
+ });
137
+}
138
+
139
+// 3. Check if organization has required connections
140
+async function getOrganizationTools(organizationId: string) {
141
+ return await composio.tools.get(organizationId, {
142
+ toolkits: ['slack', 'github', 'jira'],
143
+ });
144
+}
145
+
146
+// Usage in your API endpoint
147
+app.post('/api/slack/message', async (req, res) => {
148
+ const { channel, message } = req.body;
149
+ const organizationId = req.user.organizationId; // Get from your auth system
150
+
151
+ // Verify user has permission to send messages for this organization
152
+ if (!(await userCanSendMessages(req.user.id, organizationId))) {
153
+ return res.status(403).json({ error: 'Insufficient permissions' });
154
+ }
155
+
156
+ try {
157
+ const result = await sendSlackMessage(organizationId, channel, message);
158
+ res.json(result.data);
159
+ } catch (error) {
160
+ res.status(500).json({ error: 'Failed to send message' });
161
+ }
162
+});
163
+```
164
+
165
+#### Organization vs Individual User Pattern
166
+
167
+```typescript
168
+// ❌ Wrong: Using individual user IDs when apps are connected at org level
169
+const userTools = await composio.tools.get(req.user.id, {
170
+ toolkits: ['slack'], // This would fail if Slack is connected to the org, not the user
171
+});
172
+
173
+// ✅ Correct: Using organization ID for org-level connections
174
+const orgTools = await composio.tools.get(req.user.organizationId, {
175
+ toolkits: ['slack'], // This works because Slack is connected to the organization
176
+});
177
+
178
+// ✅ Hybrid: Some tools at user level, some at org level
179
+const userPersonalTools = await composio.tools.get(req.user.id, {
180
+ toolkits: ['gmail'], // User's personal Gmail
181
+});
182
+
183
+const orgSharedTools = await composio.tools.get(req.user.organizationId, {
184
+ toolkits: ['slack', 'jira'], // Organization's shared tools
185
+});
186
+```
187
+
188
### Example: Multi-User Application Flow
189
190
```typescript