1 use crate::ar_date_format;
2 use chrono::{DateTime, Utc};
3 use serde::{Deserialize, Serialize};
4 use tsync::tsync;
5
6 #[derive(Serialize, Deserialize, Debug, Clone)]
7 pub struct AuthApp {
8 pub id: String,
9 pub secret: Option<String>,
10 pub name: String,
11 #[serde(with = "ar_date_format")]
12 pub created_at: DateTime<Utc>,
13 #[serde(with = "ar_date_format")]
14 pub updated_at: DateTime<Utc>,
15 }
16
17 #[derive(Serialize, Deserialize, Debug, Clone)]
18 pub struct AuthAppCreate {
19 pub name: String,
20 pub description: String,
21 }
22
23 /// A public OAuth client registered against an AuthApp for the hosted
24 /// Authorization Code + PKCE flow.
25 ///
26 /// These are public clients: no client secret is issued, so security rests on
27 /// PKCE plus the `redirect_uris` allowlist. `redirect_uris` is a newline-
28 /// separated list. `client_id` is the public identifier (prefixed `auc_`) sent
29 /// in the `/authorize` request.
30 #[derive(Serialize, Deserialize, Debug, Clone)]
31 #[tsync]
32 pub struct AuthAppClient {
33 pub id: i64,
34 pub client_id: String,
35 pub name: String,
36 pub redirect_uris: String,
37 pub confidential: bool,
38 pub auth_app_id: String,
39 #[serde(with = "ar_date_format")]
40 pub created_at: DateTime<Utc>,
41 #[serde(with = "ar_date_format")]
42 pub updated_at: DateTime<Utc>,
43 }
44
45 /// Request body for registering a new public OAuth client on an AuthApp.
46 /// `redirect_uris` is a newline-separated allowlist; each entry must be https,
47 /// a loopback http URL, or a custom scheme (native apps).
48 #[derive(Serialize, Deserialize, Debug, Clone)]
49 #[tsync]
50 pub struct AuthAppClientCreate {
51 pub name: String,
52 pub redirect_uris: String,
53 }
54
55 #[cfg(test)]
56 mod tests {
57 use super::*;
58 use serde_json::json;
59 #[test]
60 fn test_auth_app_create() {
61 let auth_app_create = AuthAppCreate {
62 name: "test".to_owned(),
63 description: "test".to_owned(),
64 };
65 let json = json!({
66 "name": "test",
67 "description": "test",
68 });
69 assert_eq!(serde_json::to_value(auth_app_create).unwrap(), json);
70 }
71 }