Skip to main content

a3s_ahp/
auth.rs

1//! Authentication and authorization
2
3use serde::{Deserialize, Serialize};
4
5/// Authentication configuration
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct AuthConfig {
8    pub method: AuthMethod,
9}
10
11/// Authentication methods
12#[derive(Debug, Clone, Serialize, Deserialize)]
13#[serde(tag = "type", rename_all = "snake_case")]
14pub enum AuthMethod {
15    /// No authentication (local stdio, trusted environment)
16    None,
17
18    /// API key authentication
19    ApiKey { key: String },
20
21    /// Bearer token authentication
22    Bearer { token: String },
23
24    /// Mutual TLS (client and server certificates)
25    MutualTls {
26        cert_path: String,
27        key_path: String,
28        ca_path: Option<String>,
29    },
30
31    /// OAuth 2.0
32    OAuth {
33        client_id: String,
34        client_secret: String,
35        token_url: String,
36    },
37}
38
39impl Default for AuthConfig {
40    fn default() -> Self {
41        Self {
42            method: AuthMethod::None,
43        }
44    }
45}
46
47impl AuthConfig {
48    pub fn none() -> Self {
49        Self {
50            method: AuthMethod::None,
51        }
52    }
53
54    pub fn api_key(key: impl Into<String>) -> Self {
55        Self {
56            method: AuthMethod::ApiKey { key: key.into() },
57        }
58    }
59
60    pub fn bearer(token: impl Into<String>) -> Self {
61        Self {
62            method: AuthMethod::Bearer {
63                token: token.into(),
64            },
65        }
66    }
67}