1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait WebAuthnApi: Send + Sync {
29 async fn assertion_options<'a>(
31 &self,
32 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
33 ) -> Result<models::WebAuthnLoginAssertionOptionsResponseModel, Error<AssertionOptionsError>>;
34
35 async fn attestation_options<'a>(
37 &self,
38 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
39 ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error<AttestationOptionsError>>;
40
41 async fn delete<'a>(
43 &self,
44 id: uuid::Uuid,
45 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
46 ) -> Result<(), Error<DeleteError>>;
47
48 async fn get(
50 &self,
51 ) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<GetError>>;
52
53 async fn post<'a>(
55 &self,
56 web_authn_login_credential_create_request_model: Option<
57 models::WebAuthnLoginCredentialCreateRequestModel,
58 >,
59 ) -> Result<(), Error<PostError>>;
60
61 async fn update_credential<'a>(
63 &self,
64 web_authn_login_credential_update_request_model: Option<
65 models::WebAuthnLoginCredentialUpdateRequestModel,
66 >,
67 ) -> Result<(), Error<UpdateCredentialError>>;
68}
69
70pub struct WebAuthnApiClient {
71 configuration: Arc<configuration::Configuration>,
72}
73
74impl WebAuthnApiClient {
75 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
76 Self { configuration }
77 }
78}
79
80#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
81#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
82impl WebAuthnApi for WebAuthnApiClient {
83 async fn assertion_options<'a>(
84 &self,
85 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
86 ) -> Result<models::WebAuthnLoginAssertionOptionsResponseModel, Error<AssertionOptionsError>>
87 {
88 let local_var_configuration = &self.configuration;
89
90 let local_var_client = &local_var_configuration.client;
91
92 let local_var_uri_str = format!(
93 "{}/webauthn/assertion-options",
94 local_var_configuration.base_path
95 );
96 let mut local_var_req_builder =
97 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100 local_var_req_builder = local_var_req_builder
101 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
102 }
103 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
104 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
105 };
106 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
107
108 let local_var_req = local_var_req_builder.build()?;
109 let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111 let local_var_status = local_var_resp.status();
112 let local_var_content_type = local_var_resp
113 .headers()
114 .get("content-type")
115 .and_then(|v| v.to_str().ok())
116 .unwrap_or("application/octet-stream");
117 let local_var_content_type = super::ContentType::from(local_var_content_type);
118 let local_var_content = local_var_resp.text().await?;
119
120 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
121 match local_var_content_type {
122 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
123 ContentType::Text => {
124 return Err(Error::from(serde_json::Error::custom(
125 "Received `text/plain` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`",
126 )));
127 }
128 ContentType::Unsupported(local_var_unknown_type) => {
129 return Err(Error::from(serde_json::Error::custom(format!(
130 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`"
131 ))));
132 }
133 }
134 } else {
135 let local_var_entity: Option<AssertionOptionsError> =
136 serde_json::from_str(&local_var_content).ok();
137 let local_var_error = ResponseContent {
138 status: local_var_status,
139 content: local_var_content,
140 entity: local_var_entity,
141 };
142 Err(Error::ResponseError(local_var_error))
143 }
144 }
145
146 async fn attestation_options<'a>(
147 &self,
148 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
149 ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error<AttestationOptionsError>>
150 {
151 let local_var_configuration = &self.configuration;
152
153 let local_var_client = &local_var_configuration.client;
154
155 let local_var_uri_str = format!(
156 "{}/webauthn/attestation-options",
157 local_var_configuration.base_path
158 );
159 let mut local_var_req_builder =
160 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
161
162 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
163 local_var_req_builder = local_var_req_builder
164 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
165 }
166 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
167 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
168 };
169 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
170
171 let local_var_req = local_var_req_builder.build()?;
172 let local_var_resp = local_var_client.execute(local_var_req).await?;
173
174 let local_var_status = local_var_resp.status();
175 let local_var_content_type = local_var_resp
176 .headers()
177 .get("content-type")
178 .and_then(|v| v.to_str().ok())
179 .unwrap_or("application/octet-stream");
180 let local_var_content_type = super::ContentType::from(local_var_content_type);
181 let local_var_content = local_var_resp.text().await?;
182
183 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
184 match local_var_content_type {
185 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
186 ContentType::Text => {
187 return Err(Error::from(serde_json::Error::custom(
188 "Received `text/plain` content type response that cannot be converted to `models::WebAuthnCredentialCreateOptionsResponseModel`",
189 )));
190 }
191 ContentType::Unsupported(local_var_unknown_type) => {
192 return Err(Error::from(serde_json::Error::custom(format!(
193 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WebAuthnCredentialCreateOptionsResponseModel`"
194 ))));
195 }
196 }
197 } else {
198 let local_var_entity: Option<AttestationOptionsError> =
199 serde_json::from_str(&local_var_content).ok();
200 let local_var_error = ResponseContent {
201 status: local_var_status,
202 content: local_var_content,
203 entity: local_var_entity,
204 };
205 Err(Error::ResponseError(local_var_error))
206 }
207 }
208
209 async fn delete<'a>(
210 &self,
211 id: uuid::Uuid,
212 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
213 ) -> Result<(), Error<DeleteError>> {
214 let local_var_configuration = &self.configuration;
215
216 let local_var_client = &local_var_configuration.client;
217
218 let local_var_uri_str = format!(
219 "{}/webauthn/{id}/delete",
220 local_var_configuration.base_path,
221 id = id
222 );
223 let mut local_var_req_builder =
224 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
225
226 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227 local_var_req_builder = local_var_req_builder
228 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229 }
230 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
231 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
232 };
233 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
234
235 let local_var_req = local_var_req_builder.build()?;
236 let local_var_resp = local_var_client.execute(local_var_req).await?;
237
238 let local_var_status = local_var_resp.status();
239 let local_var_content = local_var_resp.text().await?;
240
241 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
242 Ok(())
243 } else {
244 let local_var_entity: Option<DeleteError> =
245 serde_json::from_str(&local_var_content).ok();
246 let local_var_error = ResponseContent {
247 status: local_var_status,
248 content: local_var_content,
249 entity: local_var_entity,
250 };
251 Err(Error::ResponseError(local_var_error))
252 }
253 }
254
255 async fn get(
256 &self,
257 ) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<GetError>> {
258 let local_var_configuration = &self.configuration;
259
260 let local_var_client = &local_var_configuration.client;
261
262 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
263 let mut local_var_req_builder =
264 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
265
266 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267 local_var_req_builder = local_var_req_builder
268 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
269 }
270 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
271 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
272 };
273
274 let local_var_req = local_var_req_builder.build()?;
275 let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277 let local_var_status = local_var_resp.status();
278 let local_var_content_type = local_var_resp
279 .headers()
280 .get("content-type")
281 .and_then(|v| v.to_str().ok())
282 .unwrap_or("application/octet-stream");
283 let local_var_content_type = super::ContentType::from(local_var_content_type);
284 let local_var_content = local_var_resp.text().await?;
285
286 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
287 match local_var_content_type {
288 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
289 ContentType::Text => {
290 return Err(Error::from(serde_json::Error::custom(
291 "Received `text/plain` content type response that cannot be converted to `models::WebAuthnCredentialResponseModelListResponseModel`",
292 )));
293 }
294 ContentType::Unsupported(local_var_unknown_type) => {
295 return Err(Error::from(serde_json::Error::custom(format!(
296 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WebAuthnCredentialResponseModelListResponseModel`"
297 ))));
298 }
299 }
300 } else {
301 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
302 let local_var_error = ResponseContent {
303 status: local_var_status,
304 content: local_var_content,
305 entity: local_var_entity,
306 };
307 Err(Error::ResponseError(local_var_error))
308 }
309 }
310
311 async fn post<'a>(
312 &self,
313 web_authn_login_credential_create_request_model: Option<
314 models::WebAuthnLoginCredentialCreateRequestModel,
315 >,
316 ) -> Result<(), Error<PostError>> {
317 let local_var_configuration = &self.configuration;
318
319 let local_var_client = &local_var_configuration.client;
320
321 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
322 let mut local_var_req_builder =
323 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
324
325 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
326 local_var_req_builder = local_var_req_builder
327 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
328 }
329 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
330 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
331 };
332 local_var_req_builder =
333 local_var_req_builder.json(&web_authn_login_credential_create_request_model);
334
335 let local_var_req = local_var_req_builder.build()?;
336 let local_var_resp = local_var_client.execute(local_var_req).await?;
337
338 let local_var_status = local_var_resp.status();
339 let local_var_content = local_var_resp.text().await?;
340
341 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
342 Ok(())
343 } else {
344 let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
345 let local_var_error = ResponseContent {
346 status: local_var_status,
347 content: local_var_content,
348 entity: local_var_entity,
349 };
350 Err(Error::ResponseError(local_var_error))
351 }
352 }
353
354 async fn update_credential<'a>(
355 &self,
356 web_authn_login_credential_update_request_model: Option<
357 models::WebAuthnLoginCredentialUpdateRequestModel,
358 >,
359 ) -> Result<(), Error<UpdateCredentialError>> {
360 let local_var_configuration = &self.configuration;
361
362 let local_var_client = &local_var_configuration.client;
363
364 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
365 let mut local_var_req_builder =
366 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
367
368 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
369 local_var_req_builder = local_var_req_builder
370 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
371 }
372 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
373 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
374 };
375 local_var_req_builder =
376 local_var_req_builder.json(&web_authn_login_credential_update_request_model);
377
378 let local_var_req = local_var_req_builder.build()?;
379 let local_var_resp = local_var_client.execute(local_var_req).await?;
380
381 let local_var_status = local_var_resp.status();
382 let local_var_content = local_var_resp.text().await?;
383
384 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
385 Ok(())
386 } else {
387 let local_var_entity: Option<UpdateCredentialError> =
388 serde_json::from_str(&local_var_content).ok();
389 let local_var_error = ResponseContent {
390 status: local_var_status,
391 content: local_var_content,
392 entity: local_var_entity,
393 };
394 Err(Error::ResponseError(local_var_error))
395 }
396 }
397}
398
399#[derive(Debug, Clone, Serialize, Deserialize)]
401#[serde(untagged)]
402pub enum AssertionOptionsError {
403 UnknownValue(serde_json::Value),
404}
405#[derive(Debug, Clone, Serialize, Deserialize)]
407#[serde(untagged)]
408pub enum AttestationOptionsError {
409 UnknownValue(serde_json::Value),
410}
411#[derive(Debug, Clone, Serialize, Deserialize)]
413#[serde(untagged)]
414pub enum DeleteError {
415 UnknownValue(serde_json::Value),
416}
417#[derive(Debug, Clone, Serialize, Deserialize)]
419#[serde(untagged)]
420pub enum GetError {
421 UnknownValue(serde_json::Value),
422}
423#[derive(Debug, Clone, Serialize, Deserialize)]
425#[serde(untagged)]
426pub enum PostError {
427 UnknownValue(serde_json::Value),
428}
429#[derive(Debug, Clone, Serialize, Deserialize)]
431#[serde(untagged)]
432pub enum UpdateCredentialError {
433 UnknownValue(serde_json::Value),
434}