Skip to main content

openauth_plugins/oauth_proxy/
options.rs

1use serde::Serialize;
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
4pub struct OAuthProxyOptions {
5    #[serde(skip_serializing_if = "Option::is_none", rename = "currentURL")]
6    pub current_url: Option<String>,
7    #[serde(skip_serializing_if = "Option::is_none", rename = "productionURL")]
8    pub production_url: Option<String>,
9    #[serde(rename = "maxAge")]
10    pub max_age: u64,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub secret: Option<String>,
13}
14
15impl Default for OAuthProxyOptions {
16    fn default() -> Self {
17        Self {
18            current_url: None,
19            production_url: None,
20            max_age: 60,
21            secret: None,
22        }
23    }
24}
25
26impl OAuthProxyOptions {
27    pub fn new() -> Self {
28        Self::default()
29    }
30
31    #[must_use]
32    pub fn current_url(mut self, current_url: impl Into<String>) -> Self {
33        self.current_url = Some(current_url.into());
34        self
35    }
36
37    #[must_use]
38    pub fn production_url(mut self, production_url: impl Into<String>) -> Self {
39        self.production_url = Some(production_url.into());
40        self
41    }
42
43    #[must_use]
44    pub fn max_age(mut self, max_age: u64) -> Self {
45        self.max_age = max_age;
46        self
47    }
48
49    #[must_use]
50    pub fn secret(mut self, secret: impl Into<String>) -> Self {
51        self.secret = Some(secret.into());
52        self
53    }
54
55    pub(crate) fn to_value(&self) -> serde_json::Value {
56        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
57    }
58}