Skip to main content

mas_iana/
oauth.rs

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