mas_iana/
oauth.rs

1// Copyright 2024 New Vector Ltd.
2// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
6
7#![allow(clippy::doc_markdown)]
8
9//! Enums from the "OAuth Parameters" IANA registry
10//! See <https://www.iana.org/assignments/jose/jose.xhtml>
11
12// Do not edit this file manually
13
14/// OAuth Access Token Type
15///
16/// Source: <http://www.iana.org/assignments/oauth-parameters/token-types.csv>
17#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
18#[non_exhaustive]
19pub enum OAuthAccessTokenType {
20    /// `Bearer`
21    Bearer,
22
23    /// `N_A`
24    Na,
25
26    /// `PoP`
27    PoP,
28
29    /// `DPoP`
30    DPoP,
31
32    /// An unknown value.
33    Unknown(String),
34}
35
36impl core::fmt::Display for OAuthAccessTokenType {
37    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
38        match self {
39            Self::Bearer => write!(f, "Bearer"),
40            Self::Na => write!(f, "N_A"),
41            Self::PoP => write!(f, "PoP"),
42            Self::DPoP => write!(f, "DPoP"),
43            Self::Unknown(value) => write!(f, "{value}"),
44        }
45    }
46}
47
48impl core::str::FromStr for OAuthAccessTokenType {
49    type Err = core::convert::Infallible;
50
51    fn from_str(s: &str) -> Result<Self, Self::Err> {
52        match s {
53            "Bearer" => Ok(Self::Bearer),
54            "N_A" => Ok(Self::Na),
55            "PoP" => Ok(Self::PoP),
56            "DPoP" => Ok(Self::DPoP),
57            value => Ok(Self::Unknown(value.to_owned())),
58        }
59    }
60}
61
62impl<'de> serde::Deserialize<'de> for OAuthAccessTokenType {
63    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
64    where
65        D: serde::de::Deserializer<'de>,
66    {
67        let s = String::deserialize(deserializer)?;
68        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
69    }
70}
71
72impl serde::Serialize for OAuthAccessTokenType {
73    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
74    where
75        S: serde::ser::Serializer,
76    {
77        serializer.serialize_str(&self.to_string())
78    }
79}
80
81impl schemars::JsonSchema for OAuthAccessTokenType {
82    fn schema_name() -> std::borrow::Cow<'static, str> {
83        std::borrow::Cow::Borrowed("OAuthAccessTokenType")
84    }
85
86    #[allow(clippy::too_many_lines)]
87    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
88        let enums = vec![
89            // ---
90            schemars::json_schema!({
91                "const": "Bearer",
92            }),
93            // ---
94            schemars::json_schema!({
95                "const": "N_A",
96            }),
97            // ---
98            schemars::json_schema!({
99                "const": "PoP",
100            }),
101            // ---
102            schemars::json_schema!({
103                "const": "DPoP",
104            }),
105        ];
106
107        let description = r"OAuth Access Token Type";
108        schemars::json_schema!({
109            "description": description,
110            "anyOf": enums,
111        })
112    }
113}
114
115/// OAuth Authorization Endpoint Response Type
116///
117/// Source: <http://www.iana.org/assignments/oauth-parameters/endpoint.csv>
118#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
119pub enum OAuthAuthorizationEndpointResponseType {
120    /// `code`
121    Code,
122
123    /// `code id_token`
124    CodeIdToken,
125
126    /// `code id_token token`
127    CodeIdTokenToken,
128
129    /// `code token`
130    CodeToken,
131
132    /// `id_token`
133    IdToken,
134
135    /// `id_token token`
136    IdTokenToken,
137
138    /// `none`
139    None,
140
141    /// `token`
142    Token,
143}
144
145impl core::fmt::Display for OAuthAuthorizationEndpointResponseType {
146    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
147        match self {
148            Self::Code => write!(f, "code"),
149            Self::CodeIdToken => write!(f, "code id_token"),
150            Self::CodeIdTokenToken => write!(f, "code id_token token"),
151            Self::CodeToken => write!(f, "code token"),
152            Self::IdToken => write!(f, "id_token"),
153            Self::IdTokenToken => write!(f, "id_token token"),
154            Self::None => write!(f, "none"),
155            Self::Token => write!(f, "token"),
156        }
157    }
158}
159
160impl core::str::FromStr for OAuthAuthorizationEndpointResponseType {
161    type Err = crate::ParseError;
162
163    fn from_str(s: &str) -> Result<Self, Self::Err> {
164        match s {
165            "code" => Ok(Self::Code),
166            "code id_token" => Ok(Self::CodeIdToken),
167            "code id_token token" => Ok(Self::CodeIdTokenToken),
168            "code token" => Ok(Self::CodeToken),
169            "id_token" => Ok(Self::IdToken),
170            "id_token token" => Ok(Self::IdTokenToken),
171            "none" => Ok(Self::None),
172            "token" => Ok(Self::Token),
173            _ => Err(crate::ParseError::new()),
174        }
175    }
176}
177
178impl<'de> serde::Deserialize<'de> for OAuthAuthorizationEndpointResponseType {
179    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
180    where
181        D: serde::de::Deserializer<'de>,
182    {
183        let s = String::deserialize(deserializer)?;
184        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
185    }
186}
187
188impl serde::Serialize for OAuthAuthorizationEndpointResponseType {
189    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
190    where
191        S: serde::ser::Serializer,
192    {
193        serializer.serialize_str(&self.to_string())
194    }
195}
196
197impl schemars::JsonSchema for OAuthAuthorizationEndpointResponseType {
198    fn schema_name() -> std::borrow::Cow<'static, str> {
199        std::borrow::Cow::Borrowed("OAuthAuthorizationEndpointResponseType")
200    }
201
202    #[allow(clippy::too_many_lines)]
203    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
204        let enums = vec![
205            // ---
206            schemars::json_schema!({
207                "const": "code",
208            }),
209            // ---
210            schemars::json_schema!({
211                "const": "code id_token",
212            }),
213            // ---
214            schemars::json_schema!({
215                "const": "code id_token token",
216            }),
217            // ---
218            schemars::json_schema!({
219                "const": "code token",
220            }),
221            // ---
222            schemars::json_schema!({
223                "const": "id_token",
224            }),
225            // ---
226            schemars::json_schema!({
227                "const": "id_token token",
228            }),
229            // ---
230            schemars::json_schema!({
231                "const": "none",
232            }),
233            // ---
234            schemars::json_schema!({
235                "const": "token",
236            }),
237        ];
238
239        let description = r"OAuth Authorization Endpoint Response Type";
240        schemars::json_schema!({
241            "description": description,
242            "anyOf": enums,
243        })
244    }
245}
246
247/// OAuth Token Type Hint
248///
249/// Source: <http://www.iana.org/assignments/oauth-parameters/token-type-hint.csv>
250#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
251#[non_exhaustive]
252pub enum OAuthTokenTypeHint {
253    /// `access_token`
254    AccessToken,
255
256    /// `refresh_token`
257    RefreshToken,
258
259    /// `pct`
260    Pct,
261
262    /// An unknown value.
263    Unknown(String),
264}
265
266impl core::fmt::Display for OAuthTokenTypeHint {
267    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
268        match self {
269            Self::AccessToken => write!(f, "access_token"),
270            Self::RefreshToken => write!(f, "refresh_token"),
271            Self::Pct => write!(f, "pct"),
272            Self::Unknown(value) => write!(f, "{value}"),
273        }
274    }
275}
276
277impl core::str::FromStr for OAuthTokenTypeHint {
278    type Err = core::convert::Infallible;
279
280    fn from_str(s: &str) -> Result<Self, Self::Err> {
281        match s {
282            "access_token" => Ok(Self::AccessToken),
283            "refresh_token" => Ok(Self::RefreshToken),
284            "pct" => Ok(Self::Pct),
285            value => Ok(Self::Unknown(value.to_owned())),
286        }
287    }
288}
289
290impl<'de> serde::Deserialize<'de> for OAuthTokenTypeHint {
291    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
292    where
293        D: serde::de::Deserializer<'de>,
294    {
295        let s = String::deserialize(deserializer)?;
296        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
297    }
298}
299
300impl serde::Serialize for OAuthTokenTypeHint {
301    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
302    where
303        S: serde::ser::Serializer,
304    {
305        serializer.serialize_str(&self.to_string())
306    }
307}
308
309impl schemars::JsonSchema for OAuthTokenTypeHint {
310    fn schema_name() -> std::borrow::Cow<'static, str> {
311        std::borrow::Cow::Borrowed("OAuthTokenTypeHint")
312    }
313
314    #[allow(clippy::too_many_lines)]
315    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
316        let enums = vec![
317            // ---
318            schemars::json_schema!({
319                "const": "access_token",
320            }),
321            // ---
322            schemars::json_schema!({
323                "const": "refresh_token",
324            }),
325            // ---
326            schemars::json_schema!({
327                "const": "pct",
328            }),
329        ];
330
331        let description = r"OAuth Token Type Hint";
332        schemars::json_schema!({
333            "description": description,
334            "anyOf": enums,
335        })
336    }
337}
338
339/// OAuth Token Endpoint Authentication Method
340///
341/// Source: <http://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv>
342#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
343#[non_exhaustive]
344pub enum OAuthClientAuthenticationMethod {
345    /// `none`
346    None,
347
348    /// `client_secret_post`
349    ClientSecretPost,
350
351    /// `client_secret_basic`
352    ClientSecretBasic,
353
354    /// `client_secret_jwt`
355    ClientSecretJwt,
356
357    /// `private_key_jwt`
358    PrivateKeyJwt,
359
360    /// `tls_client_auth`
361    TlsClientAuth,
362
363    /// `self_signed_tls_client_auth`
364    SelfSignedTlsClientAuth,
365
366    /// An unknown value.
367    Unknown(String),
368}
369
370impl core::fmt::Display for OAuthClientAuthenticationMethod {
371    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
372        match self {
373            Self::None => write!(f, "none"),
374            Self::ClientSecretPost => write!(f, "client_secret_post"),
375            Self::ClientSecretBasic => write!(f, "client_secret_basic"),
376            Self::ClientSecretJwt => write!(f, "client_secret_jwt"),
377            Self::PrivateKeyJwt => write!(f, "private_key_jwt"),
378            Self::TlsClientAuth => write!(f, "tls_client_auth"),
379            Self::SelfSignedTlsClientAuth => write!(f, "self_signed_tls_client_auth"),
380            Self::Unknown(value) => write!(f, "{value}"),
381        }
382    }
383}
384
385impl core::str::FromStr for OAuthClientAuthenticationMethod {
386    type Err = core::convert::Infallible;
387
388    fn from_str(s: &str) -> Result<Self, Self::Err> {
389        match s {
390            "none" => Ok(Self::None),
391            "client_secret_post" => Ok(Self::ClientSecretPost),
392            "client_secret_basic" => Ok(Self::ClientSecretBasic),
393            "client_secret_jwt" => Ok(Self::ClientSecretJwt),
394            "private_key_jwt" => Ok(Self::PrivateKeyJwt),
395            "tls_client_auth" => Ok(Self::TlsClientAuth),
396            "self_signed_tls_client_auth" => Ok(Self::SelfSignedTlsClientAuth),
397            value => Ok(Self::Unknown(value.to_owned())),
398        }
399    }
400}
401
402impl<'de> serde::Deserialize<'de> for OAuthClientAuthenticationMethod {
403    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
404    where
405        D: serde::de::Deserializer<'de>,
406    {
407        let s = String::deserialize(deserializer)?;
408        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
409    }
410}
411
412impl serde::Serialize for OAuthClientAuthenticationMethod {
413    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
414    where
415        S: serde::ser::Serializer,
416    {
417        serializer.serialize_str(&self.to_string())
418    }
419}
420
421impl schemars::JsonSchema for OAuthClientAuthenticationMethod {
422    fn schema_name() -> std::borrow::Cow<'static, str> {
423        std::borrow::Cow::Borrowed("OAuthClientAuthenticationMethod")
424    }
425
426    #[allow(clippy::too_many_lines)]
427    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
428        let enums = vec![
429            // ---
430            schemars::json_schema!({
431                "const": "none",
432            }),
433            // ---
434            schemars::json_schema!({
435                "const": "client_secret_post",
436            }),
437            // ---
438            schemars::json_schema!({
439                "const": "client_secret_basic",
440            }),
441            // ---
442            schemars::json_schema!({
443                "const": "client_secret_jwt",
444            }),
445            // ---
446            schemars::json_schema!({
447                "const": "private_key_jwt",
448            }),
449            // ---
450            schemars::json_schema!({
451                "const": "tls_client_auth",
452            }),
453            // ---
454            schemars::json_schema!({
455                "const": "self_signed_tls_client_auth",
456            }),
457        ];
458
459        let description = r"OAuth Token Endpoint Authentication Method";
460        schemars::json_schema!({
461            "description": description,
462            "anyOf": enums,
463        })
464    }
465}
466
467/// PKCE Code Challenge Method
468///
469/// Source: <http://www.iana.org/assignments/oauth-parameters/pkce-code-challenge-method.csv>
470#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
471#[non_exhaustive]
472pub enum PkceCodeChallengeMethod {
473    /// `plain`
474    Plain,
475
476    /// `S256`
477    S256,
478
479    /// An unknown value.
480    Unknown(String),
481}
482
483impl core::fmt::Display for PkceCodeChallengeMethod {
484    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
485        match self {
486            Self::Plain => write!(f, "plain"),
487            Self::S256 => write!(f, "S256"),
488            Self::Unknown(value) => write!(f, "{value}"),
489        }
490    }
491}
492
493impl core::str::FromStr for PkceCodeChallengeMethod {
494    type Err = core::convert::Infallible;
495
496    fn from_str(s: &str) -> Result<Self, Self::Err> {
497        match s {
498            "plain" => Ok(Self::Plain),
499            "S256" => Ok(Self::S256),
500            value => Ok(Self::Unknown(value.to_owned())),
501        }
502    }
503}
504
505impl<'de> serde::Deserialize<'de> for PkceCodeChallengeMethod {
506    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
507    where
508        D: serde::de::Deserializer<'de>,
509    {
510        let s = String::deserialize(deserializer)?;
511        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
512    }
513}
514
515impl serde::Serialize for PkceCodeChallengeMethod {
516    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
517    where
518        S: serde::ser::Serializer,
519    {
520        serializer.serialize_str(&self.to_string())
521    }
522}
523
524impl schemars::JsonSchema for PkceCodeChallengeMethod {
525    fn schema_name() -> std::borrow::Cow<'static, str> {
526        std::borrow::Cow::Borrowed("PkceCodeChallengeMethod")
527    }
528
529    #[allow(clippy::too_many_lines)]
530    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
531        let enums = vec![
532            // ---
533            schemars::json_schema!({
534                "const": "plain",
535            }),
536            // ---
537            schemars::json_schema!({
538                "const": "S256",
539            }),
540        ];
541
542        let description = r"PKCE Code Challenge Method";
543        schemars::json_schema!({
544            "description": description,
545            "anyOf": enums,
546        })
547    }
548}