kynos_openapi/model/security/
oauth.rs1use serde::{Deserialize, Serialize};
4
5use crate::{Map, model::extensions::Extensions};
6
7#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
9pub struct OAuthFlows {
10 #[serde(default, skip_serializing_if = "Option::is_none")]
12 pub implicit: Option<OAuthFlow>,
13
14 #[serde(default, skip_serializing_if = "Option::is_none")]
16 pub password: Option<OAuthFlow>,
17
18 #[serde(
20 rename = "clientCredentials",
21 default,
22 skip_serializing_if = "Option::is_none"
23 )]
24 pub client_credentials: Option<OAuthFlow>,
25
26 #[serde(
28 rename = "authorizationCode",
29 default,
30 skip_serializing_if = "Option::is_none"
31 )]
32 pub authorization_code: Option<OAuthFlow>,
33
34 #[cfg(feature = "openapi32")]
38 #[serde(
39 rename = "deviceAuthorization",
40 default,
41 skip_serializing_if = "Option::is_none"
42 )]
43 pub device_authorization: Option<OAuthFlow>,
44
45 #[serde(flatten)]
47 pub extensions: Extensions,
48}
49
50impl OAuthFlows {
51 #[must_use]
53 pub fn with_implicit(mut self, flow: OAuthFlow) -> Self {
54 self.implicit = Some(flow);
55 self
56 }
57
58 #[must_use]
60 pub fn with_password(mut self, flow: OAuthFlow) -> Self {
61 self.password = Some(flow);
62 self
63 }
64
65 #[must_use]
67 pub fn with_client_credentials(mut self, flow: OAuthFlow) -> Self {
68 self.client_credentials = Some(flow);
69 self
70 }
71
72 #[must_use]
74 pub fn with_authorization_code(mut self, flow: OAuthFlow) -> Self {
75 self.authorization_code = Some(flow);
76 self
77 }
78
79 #[cfg(feature = "openapi32")]
81 #[must_use]
82 pub fn with_device_authorization(mut self, flow: OAuthFlow) -> Self {
83 self.device_authorization = Some(flow);
84 self
85 }
86}
87
88#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
96pub struct OAuthFlow {
97 #[serde(
100 rename = "authorizationUrl",
101 default,
102 skip_serializing_if = "Option::is_none"
103 )]
104 pub authorization_url: Option<String>,
105
106 #[serde(rename = "tokenUrl", default, skip_serializing_if = "Option::is_none")]
109 pub token_url: Option<String>,
110
111 #[cfg(feature = "openapi32")]
116 #[serde(
117 rename = "deviceAuthorizationUrl",
118 default,
119 skip_serializing_if = "Option::is_none"
120 )]
121 pub device_authorization_url: Option<String>,
122
123 #[serde(
125 rename = "refreshUrl",
126 default,
127 skip_serializing_if = "Option::is_none"
128 )]
129 pub refresh_url: Option<String>,
130
131 pub scopes: Map<String>,
135
136 #[serde(flatten)]
138 pub extensions: Extensions,
139}
140
141impl OAuthFlow {
142 pub fn new(scopes: impl IntoIterator<Item = (String, String)>) -> Self {
144 Self {
145 scopes: scopes.into_iter().collect(),
146 ..Self::default()
147 }
148 }
149
150 #[must_use]
152 pub fn with_authorization_url(mut self, url: impl Into<String>) -> Self {
153 self.authorization_url = Some(url.into());
154 self
155 }
156
157 #[must_use]
159 pub fn with_token_url(mut self, url: impl Into<String>) -> Self {
160 self.token_url = Some(url.into());
161 self
162 }
163
164 #[must_use]
166 pub fn with_refresh_url(mut self, url: impl Into<String>) -> Self {
167 self.refresh_url = Some(url.into());
168 self
169 }
170
171 #[cfg(feature = "openapi32")]
175 #[must_use]
176 pub fn with_device_authorization_url(mut self, url: impl Into<String>) -> Self {
177 self.device_authorization_url = Some(url.into());
178 self
179 }
180}