rust_mcp_sdk/auth/client_auth/
registration.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct RegistrationResponse {
5 pub client_id: String,
6 #[serde(default)]
7 pub client_secret: Option<String>,
8 #[serde(default)]
9 pub client_id_issued_at: Option<u64>,
10 #[serde(default)]
11 pub client_secret_expires_at: Option<u64>,
12}
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17
18 #[test]
19 fn registration_response_with_secret() {
20 let json = r#"{
21 "client_id": "abc-123",
22 "client_secret": "sec-456",
23 "client_id_issued_at": 1700000000,
24 "client_secret_expires_at": 1700086400
25 }"#;
26 let reg: RegistrationResponse = serde_json::from_str(json).unwrap();
27 assert_eq!(reg.client_id, "abc-123");
28 assert_eq!(reg.client_secret.as_deref(), Some("sec-456"));
29 assert_eq!(reg.client_id_issued_at, Some(1700000000));
30 assert_eq!(reg.client_secret_expires_at, Some(1700086400));
31 }
32
33 #[test]
34 fn registration_response_without_secret() {
35 let json = r#"{"client_id": "pub-789"}"#;
36 let reg: RegistrationResponse = serde_json::from_str(json).unwrap();
37 assert_eq!(reg.client_id, "pub-789");
38 assert_eq!(reg.client_secret, None);
39 assert_eq!(reg.client_id_issued_at, None);
40 }
41}