Skip to main content

composio_sdk/models/
auth_configs.rs

1//! Authentication configuration management
2//!
3//! This module provides functionality to manage authentication configurations
4//! for toolkits in the Composio platform.
5//!
6//! Note: This is a translation of the Python SDK's auth_configs.py module.
7//! Full HTTP client integration is pending.
8
9use serde::{Deserialize, Serialize};
10
11/// Auth config status used for update-status path operations
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13#[serde(rename_all = "UPPERCASE")]
14pub enum AuthConfigStatus {
15    /// Enable auth config
16    Enabled,
17    /// Disable auth config
18    Disabled,
19}
20
21impl AuthConfigStatus {
22    /// Return wire-format path segment value.
23    pub fn as_str(self) -> &'static str {
24        match self {
25            Self::Enabled => "ENABLED",
26            Self::Disabled => "DISABLED",
27        }
28    }
29}
30
31/// Authentication configuration list parameters
32#[derive(Debug, Clone, Default, Serialize, Deserialize)]
33pub struct AuthConfigListParams {
34    /// Filter by whether the auth config is Composio-managed
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub is_composio_managed: Option<bool>,
37
38    /// Filter by toolkit slug
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub toolkit_slug: Option<String>,
41
42    /// Whether to show disabled auth configs
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub show_disabled: Option<bool>,
45
46    /// Search query for filtering by name or ID
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub search: Option<String>,
49
50    /// Maximum number of results to return
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub limit: Option<u32>,
53
54    /// Cursor for pagination
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub cursor: Option<String>,
57}
58
59/// Authentication configuration list response
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct AuthConfigListResponse {
62    /// List of auth configs
63    pub items: Vec<AuthConfigInfo>,
64
65    /// Next cursor for pagination
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub next_cursor: Option<String>,
68
69    /// Total number of pages
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub total_pages: Option<u32>,
72
73    /// Current page number
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub current_page: Option<u32>,
76
77    /// Total number of items
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub total_items: Option<u32>,
80}
81
82/// Authentication configuration information
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct AuthConfigInfo {
85    /// Unique identifier (NanoID)
86    pub id: String,
87
88    /// UUID identifier (deprecated)
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub uuid: Option<String>,
91
92    /// Type of auth config
93    #[serde(rename = "type")]
94    pub config_type: String,
95
96    /// Toolkit information
97    pub toolkit: ToolkitInfo,
98
99    /// Name of the auth config
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub name: Option<String>,
102
103    /// Authentication scheme
104    pub auth_scheme: String,
105
106    /// Credentials (may be masked)
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub credentials: Option<serde_json::Value>,
109
110    /// Status (ENABLED/DISABLED)
111    pub status: String,
112
113    /// Creation timestamp
114    pub created_at: String,
115
116    /// Number of connections using this auth config
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub no_of_connections: Option<u32>,
119
120    /// Tool access configuration
121    #[serde(skip_serializing_if = "Option::is_none")]
122    pub tool_access_config: Option<serde_json::Value>,
123}
124
125/// Toolkit information in auth config
126#[derive(Debug, Clone, Serialize, Deserialize)]
127pub struct ToolkitInfo {
128    /// Toolkit slug
129    pub slug: String,
130
131    /// Toolkit name
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub name: Option<String>,
134}
135
136/// Authentication configuration create parameters
137#[derive(Debug, Clone, Serialize, Deserialize)]
138pub struct AuthConfigCreateParams {
139    /// Toolkit slug
140    pub toolkit: String,
141
142    /// Authentication configuration options
143    pub options: AuthConfigOptions,
144}
145
146/// Authentication configuration options
147#[derive(Debug, Clone, Serialize, Deserialize)]
148#[serde(tag = "type")]
149pub enum AuthConfigOptions {
150    /// Custom auth config with full credentials
151    #[serde(rename = "custom")]
152    Custom {
153        /// Authentication scheme
154        auth_scheme: String,
155
156        /// Credentials for the auth config
157        credentials: serde_json::Value,
158
159        /// Tool access restrictions
160        #[serde(skip_serializing_if = "Option::is_none")]
161        restrict_to_following_tools: Option<Vec<String>>,
162    },
163
164    /// Default auth config with scopes only
165    #[serde(rename = "default")]
166    Default {
167        /// OAuth scopes
168        #[serde(skip_serializing_if = "Option::is_none")]
169        scopes: Option<Vec<String>>,
170
171        /// User-level scopes
172        #[serde(skip_serializing_if = "Option::is_none")]
173        user_scopes: Option<Vec<String>>,
174
175        /// Tool access restrictions
176        #[serde(skip_serializing_if = "Option::is_none")]
177        restrict_to_following_tools: Option<Vec<String>>,
178    },
179}
180
181/// Authentication configuration create response
182#[derive(Debug, Clone, Serialize, Deserialize)]
183pub struct AuthConfigCreateResponse {
184    /// Created auth config
185    pub auth_config: AuthConfig,
186}
187
188/// Authentication configuration
189#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct AuthConfig {
191    /// Unique identifier
192    pub id: String,
193
194    /// Toolkit information
195    pub toolkit: ToolkitInfo,
196
197    /// Authentication scheme
198    pub auth_scheme: String,
199
200    /// Whether this is Composio-managed
201    pub is_composio_managed: bool,
202
203    /// Tool access restrictions
204    #[serde(skip_serializing_if = "Option::is_none")]
205    pub restrict_to_following_tools: Option<Vec<String>>,
206}
207
208/// Authentication configuration retrieve response
209#[derive(Debug, Clone, Serialize, Deserialize)]
210pub struct AuthConfigRetrieveResponse {
211    /// Auth config ID
212    pub id: String,
213
214    /// UUID (deprecated)
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub uuid: Option<String>,
217
218    /// Type of auth config
219    #[serde(rename = "type")]
220    pub config_type: String,
221
222    /// Toolkit information
223    pub toolkit: ToolkitInfo,
224
225    /// Name
226    #[serde(skip_serializing_if = "Option::is_none")]
227    pub name: Option<String>,
228
229    /// Authentication scheme
230    pub auth_scheme: String,
231
232    /// Credentials
233    #[serde(skip_serializing_if = "Option::is_none")]
234    pub credentials: Option<serde_json::Value>,
235
236    /// Proxy configuration
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub proxy_config: Option<serde_json::Value>,
239
240    /// Expected input fields
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub expected_input_fields: Option<Vec<String>>,
243
244    /// Shared credentials
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub shared_credentials: Option<serde_json::Value>,
247}
248
249/// Authentication configuration update parameters
250#[derive(Debug, Clone, Serialize, Deserialize)]
251#[serde(tag = "type")]
252pub enum AuthConfigUpdateParams {
253    /// Update custom auth config
254    #[serde(rename = "custom")]
255    Custom {
256        /// Updated credentials
257        #[serde(skip_serializing_if = "Option::is_none")]
258        credentials: Option<serde_json::Value>,
259
260        /// Updated proxy config
261        #[serde(skip_serializing_if = "Option::is_none")]
262        proxy_config: Option<serde_json::Value>,
263
264        /// Updated tool access config
265        #[serde(skip_serializing_if = "Option::is_none")]
266        tool_access_config: Option<serde_json::Value>,
267
268        /// Updated shared credentials
269        #[serde(skip_serializing_if = "Option::is_none")]
270        shared_credentials: Option<serde_json::Value>,
271
272        /// Whether enabled for tool router
273        #[serde(skip_serializing_if = "Option::is_none")]
274        is_enabled_for_tool_router: Option<bool>,
275    },
276
277    /// Update default auth config
278    #[serde(rename = "default")]
279    Default {
280        /// Updated credentials (scopes)
281        #[serde(skip_serializing_if = "Option::is_none")]
282        credentials: Option<DefaultCredentials>,
283
284        /// Whether enabled for tool router
285        #[serde(skip_serializing_if = "Option::is_none")]
286        is_enabled_for_tool_router: Option<bool>,
287    },
288}
289
290/// Default credentials (scopes)
291#[derive(Debug, Clone, Serialize, Deserialize)]
292pub struct DefaultCredentials {
293    /// OAuth scopes
294    #[serde(skip_serializing_if = "Option::is_none")]
295    pub scopes: Option<Vec<String>>,
296
297    /// User-level scopes
298    #[serde(skip_serializing_if = "Option::is_none")]
299    pub user_scopes: Option<Vec<String>>,
300}
301
302/// Authentication configuration update response
303#[derive(Debug, Clone, Serialize, Deserialize)]
304pub struct AuthConfigUpdateResponse {
305    /// Success status
306    pub success: bool,
307
308    /// Updated auth config
309    #[serde(skip_serializing_if = "Option::is_none")]
310    pub auth_config: Option<AuthConfigInfo>,
311}
312
313/// Authentication configuration delete response
314#[derive(Debug, Clone, Serialize, Deserialize)]
315pub struct AuthConfigDeleteResponse {
316    /// Success status
317    pub success: bool,
318
319    /// Message
320    #[serde(skip_serializing_if = "Option::is_none")]
321    pub message: Option<String>,
322}
323
324/// Authentication configuration status update response
325#[derive(Debug, Clone, Serialize, Deserialize)]
326pub struct AuthConfigStatusUpdateResponse {
327    /// Success status
328    pub success: bool,
329
330    /// Updated status
331    pub status: String,
332}
333
334// Note: The AuthConfigs resource implementation is pending full HTTP client integration.
335// The data structures above are ready for use once the client supports generic HTTP methods.
336
337#[cfg(test)]
338mod tests {
339    use super::*;
340
341    #[test]
342    fn test_auth_config_list_params_default() {
343        let params = AuthConfigListParams::default();
344        assert!(params.is_composio_managed.is_none());
345        assert!(params.toolkit_slug.is_none());
346    }
347
348    #[test]
349    fn test_auth_config_options_custom_serialization() {
350        let options = AuthConfigOptions::Custom {
351            auth_scheme: "OAUTH2".to_string(),
352            credentials: serde_json::json!({"client_id": "test"}),
353            restrict_to_following_tools: None,
354        };
355
356        let json = serde_json::to_string(&options).unwrap();
357        assert!(json.contains("custom"));
358        assert!(json.contains("OAUTH2"));
359    }
360
361    #[test]
362    fn test_auth_config_status_serialization() {
363        let enabled = AuthConfigStatus::Enabled;
364        let json = serde_json::to_string(&enabled).unwrap();
365        assert_eq!(json, "\"ENABLED\"");
366        assert_eq!(enabled.as_str(), "ENABLED");
367    }
368
369    #[test]
370    fn test_auth_config_update_response_deserialization() {
371        let payload = r#"{"success":true}"#;
372        let response: AuthConfigUpdateResponse = serde_json::from_str(payload).unwrap();
373        assert!(response.success);
374    }
375
376    #[test]
377    fn test_auth_config_delete_response_deserialization() {
378        let payload = r#"{"success":true,"message":"deleted"}"#;
379        let response: AuthConfigDeleteResponse = serde_json::from_str(payload).unwrap();
380        assert!(response.success);
381        assert_eq!(response.message.as_deref(), Some("deleted"));
382    }
383
384    #[test]
385    fn test_auth_config_status_update_response_deserialization() {
386        let payload = r#"{"success":true,"status":"DISABLED"}"#;
387        let response: AuthConfigStatusUpdateResponse = serde_json::from_str(payload).unwrap();
388        assert!(response.success);
389        assert_eq!(response.status, "DISABLED");
390    }
391
392    #[test]
393    fn test_auth_config_options_default_serialization() {
394        let options = AuthConfigOptions::Default {
395            scopes: Some(vec!["repo".to_string()]),
396            user_scopes: None,
397            restrict_to_following_tools: None,
398        };
399
400        let json = serde_json::to_string(&options).unwrap();
401        assert!(json.contains("default"));
402        assert!(json.contains("repo"));
403    }
404}