Skip to content

Commit e57e43e

Browse files
fix: initiate_connection on toolset
1 parent 594dc06 commit e57e43e

File tree

1 file changed

+9
-54
lines changed

1 file changed

+9
-54
lines changed

python/composio/tools/toolset.py

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ def initiate_connection(
12921292
*,
12931293
auth_scheme: t.Optional[AuthSchemeType] = None,
12941294
auth_config: t.Optional[t.Dict[str, t.Any]] = None,
1295+
use_composio_auth: bool = True,
12951296
) -> ConnectionRequestModel:
12961297
"""
12971298
Initiates a connection with the specified integration.
@@ -1310,67 +1311,21 @@ def initiate_connection(
13101311
f"'auth_scheme' must be one of {AUTH_SCHEME_WITH_INITIATE}"
13111312
)
13121313

1313-
if integration_id is None:
1314-
if app is None:
1315-
raise InvalidParams(
1316-
message="Both `integration_id` and `app` cannot be None"
1317-
)
1318-
1319-
if auth_scheme is None:
1320-
auth_scheme = self.get_auth_scheme_for_app(app).auth_mode
1321-
1322-
if auth_scheme is not None and auth_scheme not in AUTH_SCHEME_WITH_INITIATE:
1323-
self._validate_no_auth_scheme(auth_scheme)
1324-
raise InvalidParams(
1325-
f"'auth_scheme' must be one of {AUTH_SCHEME_WITH_INITIATE}"
1326-
)
1327-
1328-
try:
1329-
integration_id = self._get_integration_for_app(
1330-
app=t.cast(
1331-
AppType,
1332-
app,
1333-
),
1334-
auth_scheme=auth_scheme,
1335-
).id
1336-
except NoItemsFound:
1337-
auth_config, use_composio_auth = self._validate_auth_config(
1338-
app, auth_scheme, auth_config
1339-
)
1340-
integration = self.create_integration(
1341-
app=app,
1342-
auth_mode=auth_scheme,
1343-
auth_config=auth_config,
1344-
use_composio_oauth_app=use_composio_auth,
1345-
)
1346-
integration_id = integration.id
1347-
1348-
connected_account_params = connected_account_params or {}
1349-
expected_params = self.get_expected_params_for_user(
1350-
auth_scheme=auth_scheme, integration_id=integration_id
1351-
)["expected_params"]
1352-
required_params = [param for param in expected_params if param.required]
1353-
unavailable_params = [
1354-
param.name
1355-
for param in required_params
1356-
if param.name not in connected_account_params
1357-
]
1358-
if unavailable_params:
1359-
raise InvalidParams(
1360-
f"Expected 'connected_account_params' to provide these params: {unavailable_params}"
1361-
)
1362-
1363-
# Populate defaults in the connected_account_params
1364-
for param in expected_params:
1365-
if param.default is not None and param.name not in connected_account_params:
1366-
connected_account_params[param.name] = param.default
1314+
if app is not None:
1315+
app_name = app if isinstance(app, str) else app.name
13671316

1317+
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
13681318
return self.client.connected_accounts.initiate(
13691319
integration_id=integration_id,
13701320
entity_id=entity_id or self.entity_id,
13711321
params=connected_account_params,
13721322
labels=labels,
13731323
redirect_url=redirect_url,
1324+
app_unique_key=app_name, # pylint: disable=E0606
1325+
name=f"{app_name}_{timestamp}",
1326+
auth_mode=auth_scheme,
1327+
auth_config=auth_config,
1328+
use_composio_auth=use_composio_auth,
13741329
)
13751330

13761331
def _validate_auth_config(

0 commit comments

Comments
 (0)