Skip to main content

romm_cli/endpoints/
client_tokens.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use super::Endpoint;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ClientTokenCreateSchema {
8    pub id: i64,
9    pub name: String,
10    pub scopes: Vec<String>,
11    pub expires_at: Option<String>,
12    pub last_used_at: Option<String>,
13    pub created_at: String,
14    pub user_id: i64,
15    pub raw_token: String,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct ExchangeClientTokenRequest {
20    pub code: String,
21}
22
23#[derive(Debug, Clone)]
24pub struct ExchangeClientToken {
25    pub code: String,
26}
27
28impl Endpoint for ExchangeClientToken {
29    type Output = ClientTokenCreateSchema;
30
31    fn method(&self) -> &'static str {
32        "POST"
33    }
34
35    fn path(&self) -> String {
36        "/api/client-tokens/exchange".into()
37    }
38
39    fn body(&self) -> Option<Value> {
40        let req = ExchangeClientTokenRequest {
41            code: self.code.clone(),
42        };
43        serde_json::to_value(&req).ok()
44    }
45}