1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum WebauthnAssertionOptionsPostError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum WebauthnAttestationOptionsPostError {
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum WebauthnGetError {
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum WebauthnIdDeletePostError {
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum WebauthnPostError {
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum WebauthnPutError {
56 UnknownValue(serde_json::Value),
57}
58
59pub async fn webauthn_assertion_options_post(
60 configuration: &configuration::Configuration,
61 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
62) -> Result<
63 models::WebAuthnLoginAssertionOptionsResponseModel,
64 Error<WebauthnAssertionOptionsPostError>,
65> {
66 let p_secret_verification_request_model = secret_verification_request_model;
68
69 let uri_str = format!("{}/webauthn/assertion-options", configuration.base_path);
70 let mut req_builder = configuration
71 .client
72 .request(reqwest::Method::POST, &uri_str);
73
74 if let Some(ref user_agent) = configuration.user_agent {
75 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76 }
77 if let Some(ref token) = configuration.oauth_access_token {
78 req_builder = req_builder.bearer_auth(token.to_owned());
79 };
80 req_builder = req_builder.json(&p_secret_verification_request_model);
81
82 let req = req_builder.build()?;
83 let resp = configuration.client.execute(req).await?;
84
85 let status = resp.status();
86 let content_type = resp
87 .headers()
88 .get("content-type")
89 .and_then(|v| v.to_str().ok())
90 .unwrap_or("application/octet-stream");
91 let content_type = super::ContentType::from(content_type);
92
93 if !status.is_client_error() && !status.is_server_error() {
94 let content = resp.text().await?;
95 match content_type {
96 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`"))),
98 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`")))),
99 }
100 } else {
101 let content = resp.text().await?;
102 let entity: Option<WebauthnAssertionOptionsPostError> = serde_json::from_str(&content).ok();
103 Err(Error::ResponseError(ResponseContent {
104 status,
105 content,
106 entity,
107 }))
108 }
109}
110
111pub async fn webauthn_attestation_options_post(
112 configuration: &configuration::Configuration,
113 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
114) -> Result<
115 models::WebAuthnCredentialCreateOptionsResponseModel,
116 Error<WebauthnAttestationOptionsPostError>,
117> {
118 let p_secret_verification_request_model = secret_verification_request_model;
120
121 let uri_str = format!("{}/webauthn/attestation-options", configuration.base_path);
122 let mut req_builder = configuration
123 .client
124 .request(reqwest::Method::POST, &uri_str);
125
126 if let Some(ref user_agent) = configuration.user_agent {
127 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
128 }
129 if let Some(ref token) = configuration.oauth_access_token {
130 req_builder = req_builder.bearer_auth(token.to_owned());
131 };
132 req_builder = req_builder.json(&p_secret_verification_request_model);
133
134 let req = req_builder.build()?;
135 let resp = configuration.client.execute(req).await?;
136
137 let status = resp.status();
138 let content_type = resp
139 .headers()
140 .get("content-type")
141 .and_then(|v| v.to_str().ok())
142 .unwrap_or("application/octet-stream");
143 let content_type = super::ContentType::from(content_type);
144
145 if !status.is_client_error() && !status.is_server_error() {
146 let content = resp.text().await?;
147 match content_type {
148 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
149 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebAuthnCredentialCreateOptionsResponseModel`"))),
150 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebAuthnCredentialCreateOptionsResponseModel`")))),
151 }
152 } else {
153 let content = resp.text().await?;
154 let entity: Option<WebauthnAttestationOptionsPostError> =
155 serde_json::from_str(&content).ok();
156 Err(Error::ResponseError(ResponseContent {
157 status,
158 content,
159 entity,
160 }))
161 }
162}
163
164pub async fn webauthn_get(
165 configuration: &configuration::Configuration,
166) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<WebauthnGetError>> {
167 let uri_str = format!("{}/webauthn", configuration.base_path);
168 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
169
170 if let Some(ref user_agent) = configuration.user_agent {
171 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172 }
173 if let Some(ref token) = configuration.oauth_access_token {
174 req_builder = req_builder.bearer_auth(token.to_owned());
175 };
176
177 let req = req_builder.build()?;
178 let resp = configuration.client.execute(req).await?;
179
180 let status = resp.status();
181 let content_type = resp
182 .headers()
183 .get("content-type")
184 .and_then(|v| v.to_str().ok())
185 .unwrap_or("application/octet-stream");
186 let content_type = super::ContentType::from(content_type);
187
188 if !status.is_client_error() && !status.is_server_error() {
189 let content = resp.text().await?;
190 match content_type {
191 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebAuthnCredentialResponseModelListResponseModel`"))),
193 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebAuthnCredentialResponseModelListResponseModel`")))),
194 }
195 } else {
196 let content = resp.text().await?;
197 let entity: Option<WebauthnGetError> = serde_json::from_str(&content).ok();
198 Err(Error::ResponseError(ResponseContent {
199 status,
200 content,
201 entity,
202 }))
203 }
204}
205
206pub async fn webauthn_id_delete_post(
207 configuration: &configuration::Configuration,
208 id: uuid::Uuid,
209 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
210) -> Result<(), Error<WebauthnIdDeletePostError>> {
211 let p_id = id;
213 let p_secret_verification_request_model = secret_verification_request_model;
214
215 let uri_str = format!(
216 "{}/webauthn/{id}/delete",
217 configuration.base_path,
218 id = crate::apis::urlencode(p_id.to_string())
219 );
220 let mut req_builder = configuration
221 .client
222 .request(reqwest::Method::POST, &uri_str);
223
224 if let Some(ref user_agent) = configuration.user_agent {
225 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
226 }
227 if let Some(ref token) = configuration.oauth_access_token {
228 req_builder = req_builder.bearer_auth(token.to_owned());
229 };
230 req_builder = req_builder.json(&p_secret_verification_request_model);
231
232 let req = req_builder.build()?;
233 let resp = configuration.client.execute(req).await?;
234
235 let status = resp.status();
236
237 if !status.is_client_error() && !status.is_server_error() {
238 Ok(())
239 } else {
240 let content = resp.text().await?;
241 let entity: Option<WebauthnIdDeletePostError> = serde_json::from_str(&content).ok();
242 Err(Error::ResponseError(ResponseContent {
243 status,
244 content,
245 entity,
246 }))
247 }
248}
249
250pub async fn webauthn_post(
251 configuration: &configuration::Configuration,
252 web_authn_login_credential_create_request_model: Option<
253 models::WebAuthnLoginCredentialCreateRequestModel,
254 >,
255) -> Result<(), Error<WebauthnPostError>> {
256 let p_web_authn_login_credential_create_request_model =
258 web_authn_login_credential_create_request_model;
259
260 let uri_str = format!("{}/webauthn", configuration.base_path);
261 let mut req_builder = configuration
262 .client
263 .request(reqwest::Method::POST, &uri_str);
264
265 if let Some(ref user_agent) = configuration.user_agent {
266 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
267 }
268 if let Some(ref token) = configuration.oauth_access_token {
269 req_builder = req_builder.bearer_auth(token.to_owned());
270 };
271 req_builder = req_builder.json(&p_web_authn_login_credential_create_request_model);
272
273 let req = req_builder.build()?;
274 let resp = configuration.client.execute(req).await?;
275
276 let status = resp.status();
277
278 if !status.is_client_error() && !status.is_server_error() {
279 Ok(())
280 } else {
281 let content = resp.text().await?;
282 let entity: Option<WebauthnPostError> = serde_json::from_str(&content).ok();
283 Err(Error::ResponseError(ResponseContent {
284 status,
285 content,
286 entity,
287 }))
288 }
289}
290
291pub async fn webauthn_put(
292 configuration: &configuration::Configuration,
293 web_authn_login_credential_update_request_model: Option<
294 models::WebAuthnLoginCredentialUpdateRequestModel,
295 >,
296) -> Result<(), Error<WebauthnPutError>> {
297 let p_web_authn_login_credential_update_request_model =
299 web_authn_login_credential_update_request_model;
300
301 let uri_str = format!("{}/webauthn", configuration.base_path);
302 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
303
304 if let Some(ref user_agent) = configuration.user_agent {
305 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
306 }
307 if let Some(ref token) = configuration.oauth_access_token {
308 req_builder = req_builder.bearer_auth(token.to_owned());
309 };
310 req_builder = req_builder.json(&p_web_authn_login_credential_update_request_model);
311
312 let req = req_builder.build()?;
313 let resp = configuration.client.execute(req).await?;
314
315 let status = resp.status();
316
317 if !status.is_client_error() && !status.is_server_error() {
318 Ok(())
319 } else {
320 let content = resp.text().await?;
321 let entity: Option<WebauthnPutError> = serde_json::from_str(&content).ok();
322 Err(Error::ResponseError(ResponseContent {
323 status,
324 content,
325 entity,
326 }))
327 }
328}