@@ -1292,6 +1292,7 @@ def initiate_connection(
1292
1292
* ,
1293
1293
auth_scheme : t .Optional [AuthSchemeType ] = None ,
1294
1294
auth_config : t .Optional [t .Dict [str , t .Any ]] = None ,
1295
+ use_composio_auth : bool = True ,
1295
1296
) -> ConnectionRequestModel :
1296
1297
"""
1297
1298
Initiates a connection with the specified integration.
@@ -1310,67 +1311,21 @@ def initiate_connection(
1310
1311
f"'auth_scheme' must be one of { AUTH_SCHEME_WITH_INITIATE } "
1311
1312
)
1312
1313
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
1367
1316
1317
+ timestamp = datetime .now ().strftime ("%Y%m%d%H%M%S" )
1368
1318
return self .client .connected_accounts .initiate (
1369
1319
integration_id = integration_id ,
1370
1320
entity_id = entity_id or self .entity_id ,
1371
1321
params = connected_account_params ,
1372
1322
labels = labels ,
1373
1323
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 ,
1374
1329
)
1375
1330
1376
1331
def _validate_auth_config (
0 commit comments