securitydept_token_set_context/backend_oidc_mode/
capabilities.rs1use securitydept_utils::secret::SecretString;
13use serde::{Deserialize, Serialize};
14
15use super::redirect::BackendOidcModeRedirectUriConfig;
16
17#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
22#[serde(rename_all = "snake_case")]
23pub enum RefreshMaterialProtectionKind {
24 #[default]
26 Passthrough,
27 Sealed,
29}
30
31#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
37#[derive(Debug, Clone, Deserialize, Default)]
38#[serde(tag = "kind", rename_all = "snake_case")]
39pub enum RefreshMaterialProtection {
40 #[default]
42 Passthrough,
43 Sealed {
45 master_key: SecretString,
47 },
48}
49
50impl RefreshMaterialProtection {
51 pub fn kind(&self) -> RefreshMaterialProtectionKind {
52 match self {
53 Self::Passthrough => RefreshMaterialProtectionKind::Passthrough,
54 Self::Sealed { .. } => RefreshMaterialProtectionKind::Sealed,
55 }
56 }
57
58 pub fn master_key(&self) -> Option<&str> {
60 match self {
61 Self::Sealed { master_key } => Some(master_key.expose_secret()),
62 Self::Passthrough => None,
63 }
64 }
65}
66
67#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
72#[serde(rename_all = "snake_case")]
73pub enum MetadataDeliveryKind {
74 #[default]
76 None,
77 Redemption,
79}
80
81#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
86#[cfg_attr(
87 feature = "config-schema",
88 schemars(bound = "MC: schemars::JsonSchema")
89)]
90#[derive(Debug, Clone, Deserialize, Default)]
91#[serde(tag = "kind", rename_all = "snake_case")]
92pub enum MetadataDelivery<MC> {
93 #[default]
96 None,
97 Redemption {
100 #[serde(flatten)]
102 config: MC,
103 },
104}
105
106impl<MC> MetadataDelivery<MC> {
107 pub fn kind(&self) -> MetadataDeliveryKind {
108 match self {
109 Self::None => MetadataDeliveryKind::None,
110 Self::Redemption { .. } => MetadataDeliveryKind::Redemption,
111 }
112 }
113}
114
115#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
119#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
120#[serde(rename_all = "snake_case")]
121pub enum PostAuthRedirectPolicyKind {
122 #[default]
124 CallerValidated,
125 Resolved,
127}
128
129#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
134#[derive(Debug, Clone, Deserialize, Default)]
135#[serde(tag = "kind", rename_all = "snake_case")]
136pub enum PostAuthRedirectPolicy {
137 #[default]
140 CallerValidated,
141 Resolved {
144 #[serde(flatten)]
146 config: BackendOidcModeRedirectUriConfig,
147 },
148}
149
150impl PostAuthRedirectPolicy {
151 pub fn kind(&self) -> PostAuthRedirectPolicyKind {
152 match self {
153 Self::CallerValidated => PostAuthRedirectPolicyKind::CallerValidated,
154 Self::Resolved { .. } => PostAuthRedirectPolicyKind::Resolved,
155 }
156 }
157}
158
159#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
169#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
170pub struct BackendOidcModeCapabilities {
171 #[serde(default)]
172 pub refresh_material_protection: RefreshMaterialProtectionKind,
173 #[serde(default)]
174 pub metadata_delivery: MetadataDeliveryKind,
175 #[serde(default)]
176 pub post_auth_redirect_policy: PostAuthRedirectPolicyKind,
177}
178
179impl Default for BackendOidcModeCapabilities {
180 fn default() -> Self {
181 Self::pure()
182 }
183}
184
185impl BackendOidcModeCapabilities {
186 pub fn pure() -> Self {
188 Self {
189 refresh_material_protection: RefreshMaterialProtectionKind::Passthrough,
190 metadata_delivery: MetadataDeliveryKind::None,
191 post_auth_redirect_policy: PostAuthRedirectPolicyKind::CallerValidated,
192 }
193 }
194
195 pub fn mediated() -> Self {
197 Self {
198 refresh_material_protection: RefreshMaterialProtectionKind::Sealed,
199 metadata_delivery: MetadataDeliveryKind::Redemption,
200 post_auth_redirect_policy: PostAuthRedirectPolicyKind::Resolved,
201 }
202 }
203}
204
205#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
207#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
208#[serde(rename_all = "snake_case")]
209pub enum BackendOidcModePreset {
210 Pure,
212 Mediated,
214}
215
216impl BackendOidcModePreset {
217 pub fn capabilities(self) -> BackendOidcModeCapabilities {
219 match self {
220 Self::Pure => BackendOidcModeCapabilities::pure(),
221 Self::Mediated => BackendOidcModeCapabilities::mediated(),
222 }
223 }
224}