Skip to main content

openauth_core/options/
cookies.rs

1/// Session cookie cache configuration.
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct CookieCacheOptions {
4    pub enabled: bool,
5    pub max_age: Option<u64>,
6    pub strategy: CookieCacheStrategy,
7    pub refresh_cache: bool,
8    pub version: Option<String>,
9}
10
11impl Default for CookieCacheOptions {
12    fn default() -> Self {
13        Self {
14            enabled: false,
15            max_age: None,
16            strategy: CookieCacheStrategy::Compact,
17            refresh_cache: false,
18            version: None,
19        }
20    }
21}
22
23impl CookieCacheOptions {
24    pub fn new() -> Self {
25        Self::default()
26    }
27
28    pub fn builder() -> Self {
29        Self::new()
30    }
31
32    #[must_use]
33    pub fn enabled(mut self, enabled: bool) -> Self {
34        self.enabled = enabled;
35        self
36    }
37
38    #[must_use]
39    pub fn max_age(mut self, max_age: u64) -> Self {
40        self.max_age = Some(max_age);
41        self
42    }
43
44    #[must_use]
45    pub fn strategy(mut self, strategy: CookieCacheStrategy) -> Self {
46        self.strategy = strategy;
47        self
48    }
49
50    #[must_use]
51    pub fn refresh_cache(mut self, refresh_cache: bool) -> Self {
52        self.refresh_cache = refresh_cache;
53        self
54    }
55
56    #[must_use]
57    pub fn version(mut self, version: impl Into<String>) -> Self {
58        self.version = Some(version.into());
59        self
60    }
61}
62
63/// Cookie cache encoding strategy.
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum CookieCacheStrategy {
66    Compact,
67    Jwt,
68    Jwe,
69}
70
71/// Cross-subdomain cookie configuration.
72#[derive(Debug, Clone, Default, PartialEq, Eq)]
73pub struct CookieConfig {
74    pub enabled: bool,
75    pub domain: Option<String>,
76}
77
78impl CookieConfig {
79    pub fn new() -> Self {
80        Self::default()
81    }
82
83    pub fn builder() -> Self {
84        Self::new()
85    }
86
87    #[must_use]
88    pub fn enabled(mut self, enabled: bool) -> Self {
89        self.enabled = enabled;
90        self
91    }
92
93    #[must_use]
94    pub fn domain(mut self, domain: impl Into<String>) -> Self {
95        self.domain = Some(domain.into());
96        self
97    }
98}