vtcode_config/core/
auth.rs1use serde::{Deserialize, Serialize};
7
8#[cfg(feature = "schema")]
9use schemars::JsonSchema;
10
11#[derive(Debug, Clone, Default, Serialize, Deserialize)]
13#[cfg_attr(feature = "schema", derive(JsonSchema))]
14pub struct AuthConfig {
15 #[serde(default)]
17 pub openrouter: OpenRouterAuthConfig,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
22#[cfg_attr(feature = "schema", derive(JsonSchema))]
23#[serde(default)]
24pub struct OpenRouterAuthConfig {
25 pub use_oauth: bool,
28
29 pub callback_port: u16,
32
33 pub auto_refresh: bool,
36
37 pub flow_timeout_secs: u64,
40}
41
42impl Default for OpenRouterAuthConfig {
43 fn default() -> Self {
44 Self {
45 use_oauth: false,
46 callback_port: 8484,
47 auto_refresh: true,
48 flow_timeout_secs: 300,
49 }
50 }
51}
52
53impl OpenRouterAuthConfig {
54 pub fn should_use_oauth(&self) -> bool {
56 self.use_oauth
57 }
58
59 pub fn callback_url(&self) -> String {
61 format!("http://localhost:{}/callback", self.callback_port)
62 }
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_default_config() {
71 let config = OpenRouterAuthConfig::default();
72 assert!(!config.use_oauth);
73 assert_eq!(config.callback_port, 8484);
74 assert!(config.auto_refresh);
75 assert_eq!(config.flow_timeout_secs, 300);
76 }
77
78 #[test]
79 fn test_callback_url() {
80 let config = OpenRouterAuthConfig {
81 callback_port: 9000,
82 ..Default::default()
83 };
84 assert_eq!(config.callback_url(), "http://localhost:9000/callback");
85 }
86}