Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | from __future__ import annotations |
| 2 | |
| 3 | import typing as t |
| 4 | |
| 5 | import typing_extensions as te |
| 6 | |
| 7 | from composio.client.types import ( |
| 8 | auth_config_create_params, |
| 9 | auth_config_create_response, |
| 10 | auth_config_delete_response, |
| 11 | auth_config_list_params, |
| 12 | auth_config_list_response, |
| 13 | auth_config_retrieve_response, |
| 14 | auth_config_update_params, |
| 15 | auth_config_update_response, |
| 16 | auth_config_update_status_response, |
| 17 | ) |
| 18 | from composio.core.models.base import Resource |
| 19 | |
| 20 | |
| 21 | class ComposioManagedAuthConfigOptions( |
| 22 | auth_config_create_params.AuthConfigUnionMember0, total=False |
| 23 | ): |
| 24 | """Options for an auth config on a Composio-managed app.""" |
| 25 | |
| 26 | managed_app_id: str |
| 27 | """The Composio-managed app to use, as ``composio_managed_auth[].managed_app_id`` |
| 28 | from ``composio.toolkits.get(slug)``. Omit to use the toolkit's default app.""" |
| 29 | |
| 30 | |
| 31 | class AuthConfigs(Resource): |
| 32 | """ |
| 33 | Manage authentication configurations. |
| 34 | """ |
| 35 | |
| 36 | def list( |
| 37 | self, |
| 38 | **query: te.Unpack[auth_config_list_params.AuthConfigListParams], |
| 39 | ) -> auth_config_list_response.AuthConfigListResponse: |
| 40 | """ |
| 41 | Lists authentication configurations based on provided filter criteria. |
| 42 | """ |
| 43 | return self._client.auth_configs.list(**query) |
| 44 | |
| 45 | @t.overload |
| 46 | def create( |
| 47 | self, toolkit: str, options: auth_config_create_params.AuthConfigUnionMember1 |
| 48 | ) -> auth_config_create_response.AuthConfig: ... |
| 49 | |
| 50 | @t.overload |
| 51 | def create( |
| 52 | self, toolkit: str, options: ComposioManagedAuthConfigOptions |
| 53 | ) -> auth_config_create_response.AuthConfig: ... |
| 54 | |
| 55 | @t.overload |
| 56 | def create( |
| 57 | self, toolkit: str, options: auth_config_create_params.AuthConfigUnionMember0 |
| 58 | ) -> auth_config_create_response.AuthConfig: ... |
| 59 | |
| 60 | def create( |
| 61 | self, |
| 62 | toolkit: str, |
| 63 | options: t.Union[ |
| 64 | auth_config_create_params.AuthConfig, ComposioManagedAuthConfigOptions |
| 65 | ], |
| 66 | ) -> auth_config_create_response.AuthConfig: |
| 67 | """ |
| 68 | Create a new auth config |
| 69 | |
| 70 | :param toolkit: The toolkit to create the auth config for. |
| 71 | :param options: The options to create the auth config with. For a |
| 72 | Composio-managed auth config, ``managed_app_id`` picks the app. |
| 73 | :return: The created auth config. |
| 74 | |
| 75 | Example: |
| 76 | toolkit = composio.toolkits.get("slack") |
| 77 | app = next(a for a in toolkit.composio_managed_auth if not a.is_default) |
| 78 | composio.auth_configs.create( |
| 79 | "slack", |
| 80 | {"type": "use_composio_managed_auth", "managed_app_id": app.managed_app_id}, |
| 81 | ) |
| 82 | """ |
| 83 | return self._client.auth_configs.create( |
| 84 | toolkit={"slug": toolkit}, auth_config=options |
| 85 | ).auth_config |
| 86 | |
| 87 | def get( |
| 88 | self, nanoid: str |
| 89 | ) -> auth_config_retrieve_response.AuthConfigRetrieveResponse: |
| 90 | """ |
| 91 | Retrieves a specific authentication configuration by its ID |
| 92 | |
| 93 | :param nanoid: The ID of the auth config to retrieve. |
| 94 | :return: The retrieved auth config. |
| 95 | """ |
| 96 | return self._client.auth_configs.retrieve(nanoid) |
| 97 | |
| 98 | @t.overload |
| 99 | def update( |
| 100 | self, nanoid: str, *, options: auth_config_update_params.Variant0 |
| 101 | ) -> auth_config_update_response.AuthConfigUpdateResponse: ... |
| 102 | |
| 103 | @t.overload |
| 104 | def update( |
| 105 | self, nanoid: str, *, options: auth_config_update_params.Variant1 |
| 106 | ) -> auth_config_update_response.AuthConfigUpdateResponse: ... |
| 107 | |
| 108 | def update( |
| 109 | self, nanoid: str, *, options: auth_config_update_params.AuthConfigUpdateParams |
| 110 | ) -> auth_config_update_response.AuthConfigUpdateResponse: |
| 111 | """ |
| 112 | Updates an existing authentication configuration. |
| 113 | |
| 114 | This method allows you to modify properties of an auth config such as credentials, |
| 115 | scopes, or tool restrictions. The update type (custom or default) determines which |
| 116 | fields can be updated. |
| 117 | |
| 118 | :param nanoid: The ID of the auth config to update. |
| 119 | :param options: The options to update the auth config with. |
| 120 | :return: The update result with success and message fields. |
| 121 | """ |
| 122 | return self._client.auth_configs.update( |
| 123 | nanoid=nanoid, |
| 124 | type=options["type"], # type: ignore |
| 125 | credentials=options.get("credentials", self._client.not_given), |
| 126 | is_enabled_for_tool_router=options.get( |
| 127 | "is_enabled_for_tool_router", self._client.not_given |
| 128 | ), |
| 129 | tool_access_config=options.get( |
| 130 | "tool_access_config", self._client.not_given |
| 131 | ), |
| 132 | ) |
| 133 | |
| 134 | def delete( |
| 135 | self, nanoid: str |
| 136 | ) -> auth_config_delete_response.AuthConfigDeleteResponse: |
| 137 | """ |
| 138 | Deletes an existing authentication configuration. |
| 139 | |
| 140 | :param nanoid: The ID of the auth config to delete. |
| 141 | :return: The deletion result with success and message fields. |
| 142 | """ |
| 143 | return self._client.auth_configs.delete(nanoid) |
| 144 | |
| 145 | def __update_status( |
| 146 | self, |
| 147 | nanoid: str, |
| 148 | status: t.Literal["ENABLED", "DISABLED"], |
| 149 | ) -> auth_config_update_status_response.AuthConfigUpdateStatusResponse: |
| 150 | return self._client.auth_configs.update_status(status, nanoid=nanoid) |
| 151 | |
| 152 | def enable( |
| 153 | self, nanoid: str |
| 154 | ) -> auth_config_update_status_response.AuthConfigUpdateStatusResponse: |
| 155 | """ |
| 156 | Enables an existing authentication configuration. |
| 157 | |
| 158 | :param nanoid: The ID of the auth config to enable. |
| 159 | :return: The status update result with success and message fields. |
| 160 | """ |
| 161 | return self.__update_status(nanoid, "ENABLED") |
| 162 | |
| 163 | def disable( |
| 164 | self, nanoid: str |
| 165 | ) -> auth_config_update_status_response.AuthConfigUpdateStatusResponse: |
| 166 | """ |
| 167 | Disables an existing authentication configuration. |
| 168 | |
| 169 | :param nanoid: The ID of the auth config to disable. |
| 170 | :return: The status update result with success and message fields. |
| 171 | """ |
| 172 | return self.__update_status(nanoid, "DISABLED") |