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 22, 18:15 UTC
wait for connection stuff
Sushmithamallesh committed
Nov 6, 2025 at 14:41 UTC
49dec971d21824392c5aec70635c58bd1059aa7c
5 files changed
+110
-42
fern/assets/images/auth-screen-example.png
Binary files /dev/null and b/fern/assets/images/auth-screen-example.png differ
fern/pages/src/tool-calling/authenticating-tools.mdx
+54
-42
@@ -85,49 +85,32 @@ User authentication requires a User ID - a unique identifier that groups connect
85
86
Redirect users to a Composio-hosted URL that handles the entire authentication process—OAuth flows, API key collection, or custom fields like subdomain. You can specify a callback URL to control where users return after authentication.
87
88
-<CodeGroup>
89
-```python Python {11-13}
90
-from composio import Composio
91
-
92
-composio = Composio(api_key="your_api_key")
93
-
94
-# Use the "AUTH CONFIG ID" from your dashboard
95
-auth_config_id = "your_auth_config_id"
96
-
97
-# Use a unique identifier for each user in your application
98
-user_id = 'user-1349-129-12'
99
-
100
-connection_request = composio.connected_accounts.link(user_id, auth_config_id, callback_url: 'https://your-app.com/callback')
101
-
102
-redirect_url = connection_request.redirect_url
103
-print(f"Visit: {redirect_url} to authenticate your account")
104
-
105
-# Wait for the connection to be established
106
-connected_account = connection_request.wait_for_connection()
107
-print(connected_account.id)
108
-```
109
-```typescript Typescript {11-13}
110
-import { Composio } from '@composio/core';
111
-
112
-const composio = new Composio({apiKey: "your_api_key"});
113
-
114
-// Use the "AUTH CONFIG ID" from your dashboard
115
-const authConfigId = 'your_auth_config_id';
116
-
117
-// Use a unique identifier for each user in your application
118
-const userId = 'user-1349-129-12';
119
-
120
-const connectionRequest = await composio.connectedAccounts.link(userId, authConfigId, {
121
- callbackUrl: 'https://your-app.com/callback'
122
-});
123
-const redirectUrl = connectionRequest.redirectUrl;
124
-console.log(`Visit: ${redirectUrl} to authenticate your account`);
88
+<Frame caption="Connect Link authentication screen">
89
+ <img
90
+ src="../../../assets/images/auth-screen-example.png"
91
+ alt="Composio authentication screen showing Gmail connection"
92
+ style={{ maxWidth: '350px', maxHeight: '400px', width: 'auto', height: 'auto', margin: '0 auto', display: 'block' }}
93
+ />
94
+</Frame>
95
126
-// Wait for the connection to be established
127
-const connectedAccount = await composio.connectedAccounts.waitForConnection(connectionRequest.id);
128
-console.log(connectedAccount.id)
96
+<CodeGroup>
97
+<SnippetCode
98
+ src="fern/snippets/authentication/python/connect-link.py"
99
+ title="Python"
100
+ startLine={1}
101
+ endLine={22}
102
+ highlightStart={11}
103
+ highlightEnd={15}
104
+/>
105
130
-````
106
+<SnippetCode
107
+ src="fern/snippets/authentication/typescript/connect-link.ts"
108
+ title="TypeScript"
109
+ startLine={1}
110
+ endLine={19}
111
+ highlightStart={11}
112
+ highlightEnd={13}
113
+/>
114
</CodeGroup>
115
116
#### Customizing Connect Link
@@ -365,9 +348,38 @@ After creating a connection, it will have one of the following statuses that ind
348
| **INACTIVE** | Connection is temporarily disabled. Re-enable it to use the connection again. |
349
| **PENDING** | Connection is being processed. Wait for it to become active. |
350
| **INITIATED** | Connection request has started but not yet completed. User may still need to complete authentication. |
368
-| **EXPIRED** | Connection credentials have expired. Re-authenticate to restore access. |
351
+| **EXPIRED** | Connection credentials have expired. Composio automatically attempts to refresh credentials before marking as expired. Re-authenticate to restore access. |
352
| **FAILED** | Connection attempt failed. Check error details and try creating a new connection. |
353
354
+<Note>
355
+When credentials expire for OAuth connections, Composio automatically attempts to refresh them using the refresh token. The connection is only marked as **EXPIRED** after multiple refresh attempts have failed.
356
+</Note>
357
+
358
+### Waiting for Connection Establishment
359
+
360
+The `waitForConnection` method allows you to poll for a connection to become active after initiating authentication. This is useful when you need to ensure a connection is ready before proceeding.
361
+
362
+<CodeGroup>
363
+<SnippetCode
364
+ src="fern/snippets/authentication/python/connect-link.py"
365
+ title="Python"
366
+ startLine={20}
367
+ endLine={29}
368
+/>
369
+
370
+<SnippetCode
371
+ src="fern/snippets/authentication/typescript/connect-link.ts"
372
+ title="TypeScript"
373
+ startLine={17}
374
+ endLine={26}
375
+/>
376
+</CodeGroup>
377
+
378
+The method continuously polls the Composio API until the connection:
379
+- Becomes **ACTIVE** (returns the connected account)
380
+- Enters a terminal state like **FAILED** or **EXPIRED** (throws an error)
381
+- Exceeds the specified timeout (throws a timeout error)
382
+
383
### Checking Connection Status
384
385
You can check the status of a connected account programmatically:
fern/snippets/authentication/python/connect-link.py
new
+29
@@ -0,0 +1,29 @@
1
+from composio import Composio
2
+
3
+composio = Composio(api_key="your_api_key")
4
+
5
+# Use the "AUTH CONFIG ID" from your dashboard
6
+auth_config_id = "your_auth_config_id"
7
+
8
+# Use a unique identifier for each user in your application
9
+user_id = 'user-1349-129-12'
10
+
11
+connection_request = composio.connected_accounts.link(
12
+ user_id=user_id,
13
+ auth_config_id=auth_config_id,
14
+ callback_url='https://your-app.com/callback'
15
+)
16
+
17
+redirect_url = connection_request.redirect_url
18
+print(f"Visit: {redirect_url} to authenticate your account")
19
+
20
+# Wait for the connection to be established
21
+connected_account = connection_request.wait_for_connection()
22
+print(connected_account.id)
23
+
24
+# Alternative: Wait with custom timeout
25
+# connected_account = connection_request.wait_for_connection(120) # 2 minute timeout
26
+
27
+# Alternative: If you only have the connection request ID (e.g., stored in database)
28
+# connection_id = connection_request.id # You can store this ID in your database
29
+# connected_account = composio.connected_accounts.wait_for_connection(connection_id, 60)
\ No newline at end of file
fern/snippets/authentication/typescript/connect-link.ts
new
+26
@@ -0,0 +1,26 @@
1
+import { Composio } from '@composio/core';
2
+
3
+const composio = new Composio({apiKey: "your_api_key"});
4
+
5
+// Use the "AUTH CONFIG ID" from your dashboard
6
+const authConfigId = 'your_auth_config_id';
7
+
8
+// Use a unique identifier for each user in your application
9
+const userId = 'user-1349-129-12';
10
+
11
+const connectionRequest = await composio.connectedAccounts.link(userId, authConfigId, {
12
+ callbackUrl: 'https://your-app.com/callback'
13
+});
14
+const redirectUrl = connectionRequest.redirectUrl;
15
+console.log(`Visit: ${redirectUrl} to authenticate your account`);
16
+
17
+// Wait for the connection to be established
18
+const connectedAccount = await connectionRequest.waitForConnection();
19
+console.log(connectedAccount.id);
20
+
21
+// Alternative: Wait with custom timeout
22
+// const connectedAccount = await connectionRequest.waitForConnection(120000); // 2 minutes
23
+
24
+// Alternative: If you only have the connection request ID (e.g., stored in database)
25
+// const connectionId = connectionRequest.id; // You can store this ID in your database
26
+// const connectedAccount = await composio.connectedAccounts.waitForConnection(connectionId, 60000);
\ No newline at end of file
fern/vapidocs
new
+1
@@ -0,0 +1 @@
1
+Subproject commit aee1e2bffe7153fa2a373e246234f9c24994f2f9