bitwarden_api_api/apis/
web_authn_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use 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::{AuthRequired, 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    /// POST /webauthn/assertion-options
30    async fn assertion_options<'a>(
31        &self,
32        secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
33    ) -> Result<models::WebAuthnLoginAssertionOptionsResponseModel, Error<AssertionOptionsError>>;
34
35    /// POST /webauthn/attestation-options
36    async fn attestation_options<'a>(
37        &self,
38        secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
39    ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error<AttestationOptionsError>>;
40
41    /// POST /webauthn/{id}/delete
42    async fn delete<'a>(
43        &self,
44        id: uuid::Uuid,
45        secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
46    ) -> Result<(), Error<DeleteError>>;
47
48    /// GET /webauthn
49    async fn get(
50        &self,
51    ) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<GetError>>;
52
53    /// POST /webauthn
54    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    /// PUT /webauthn
62    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_token) = local_var_configuration.oauth_access_token {
100            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
101        };
102        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
103        local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
104
105        let local_var_req = local_var_req_builder.build()?;
106        let local_var_resp = local_var_client.execute(local_var_req).await?;
107
108        let local_var_status = local_var_resp.status();
109        let local_var_content_type = local_var_resp
110            .headers()
111            .get("content-type")
112            .and_then(|v| v.to_str().ok())
113            .unwrap_or("application/octet-stream");
114        let local_var_content_type = super::ContentType::from(local_var_content_type);
115        let local_var_content = local_var_resp.text().await?;
116
117        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118            match local_var_content_type {
119                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
120                ContentType::Text => {
121                    return Err(Error::from(serde_json::Error::custom(
122                        "Received `text/plain` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`",
123                    )));
124                }
125                ContentType::Unsupported(local_var_unknown_type) => {
126                    return Err(Error::from(serde_json::Error::custom(format!(
127                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`"
128                    ))));
129                }
130            }
131        } else {
132            let local_var_entity: Option<AssertionOptionsError> =
133                serde_json::from_str(&local_var_content).ok();
134            let local_var_error = ResponseContent {
135                status: local_var_status,
136                content: local_var_content,
137                entity: local_var_entity,
138            };
139            Err(Error::ResponseError(local_var_error))
140        }
141    }
142
143    async fn attestation_options<'a>(
144        &self,
145        secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
146    ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error<AttestationOptionsError>>
147    {
148        let local_var_configuration = &self.configuration;
149
150        let local_var_client = &local_var_configuration.client;
151
152        let local_var_uri_str = format!(
153            "{}/webauthn/attestation-options",
154            local_var_configuration.base_path
155        );
156        let mut local_var_req_builder =
157            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
158
159        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
160            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
161        };
162        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
163        local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
164
165        let local_var_req = local_var_req_builder.build()?;
166        let local_var_resp = local_var_client.execute(local_var_req).await?;
167
168        let local_var_status = local_var_resp.status();
169        let local_var_content_type = local_var_resp
170            .headers()
171            .get("content-type")
172            .and_then(|v| v.to_str().ok())
173            .unwrap_or("application/octet-stream");
174        let local_var_content_type = super::ContentType::from(local_var_content_type);
175        let local_var_content = local_var_resp.text().await?;
176
177        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
178            match local_var_content_type {
179                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
180                ContentType::Text => {
181                    return Err(Error::from(serde_json::Error::custom(
182                        "Received `text/plain` content type response that cannot be converted to `models::WebAuthnCredentialCreateOptionsResponseModel`",
183                    )));
184                }
185                ContentType::Unsupported(local_var_unknown_type) => {
186                    return Err(Error::from(serde_json::Error::custom(format!(
187                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WebAuthnCredentialCreateOptionsResponseModel`"
188                    ))));
189                }
190            }
191        } else {
192            let local_var_entity: Option<AttestationOptionsError> =
193                serde_json::from_str(&local_var_content).ok();
194            let local_var_error = ResponseContent {
195                status: local_var_status,
196                content: local_var_content,
197                entity: local_var_entity,
198            };
199            Err(Error::ResponseError(local_var_error))
200        }
201    }
202
203    async fn delete<'a>(
204        &self,
205        id: uuid::Uuid,
206        secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
207    ) -> Result<(), Error<DeleteError>> {
208        let local_var_configuration = &self.configuration;
209
210        let local_var_client = &local_var_configuration.client;
211
212        let local_var_uri_str = format!(
213            "{}/webauthn/{id}/delete",
214            local_var_configuration.base_path,
215            id = id
216        );
217        let mut local_var_req_builder =
218            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
219
220        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
221            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
222        };
223        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
224        local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
225
226        let local_var_req = local_var_req_builder.build()?;
227        let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229        let local_var_status = local_var_resp.status();
230        let local_var_content = local_var_resp.text().await?;
231
232        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
233            Ok(())
234        } else {
235            let local_var_entity: Option<DeleteError> =
236                serde_json::from_str(&local_var_content).ok();
237            let local_var_error = ResponseContent {
238                status: local_var_status,
239                content: local_var_content,
240                entity: local_var_entity,
241            };
242            Err(Error::ResponseError(local_var_error))
243        }
244    }
245
246    async fn get(
247        &self,
248    ) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<GetError>> {
249        let local_var_configuration = &self.configuration;
250
251        let local_var_client = &local_var_configuration.client;
252
253        let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
254        let mut local_var_req_builder =
255            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
256
257        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
258            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
259        };
260        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
261
262        let local_var_req = local_var_req_builder.build()?;
263        let local_var_resp = local_var_client.execute(local_var_req).await?;
264
265        let local_var_status = local_var_resp.status();
266        let local_var_content_type = local_var_resp
267            .headers()
268            .get("content-type")
269            .and_then(|v| v.to_str().ok())
270            .unwrap_or("application/octet-stream");
271        let local_var_content_type = super::ContentType::from(local_var_content_type);
272        let local_var_content = local_var_resp.text().await?;
273
274        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
275            match local_var_content_type {
276                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
277                ContentType::Text => {
278                    return Err(Error::from(serde_json::Error::custom(
279                        "Received `text/plain` content type response that cannot be converted to `models::WebAuthnCredentialResponseModelListResponseModel`",
280                    )));
281                }
282                ContentType::Unsupported(local_var_unknown_type) => {
283                    return Err(Error::from(serde_json::Error::custom(format!(
284                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WebAuthnCredentialResponseModelListResponseModel`"
285                    ))));
286                }
287            }
288        } else {
289            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
290            let local_var_error = ResponseContent {
291                status: local_var_status,
292                content: local_var_content,
293                entity: local_var_entity,
294            };
295            Err(Error::ResponseError(local_var_error))
296        }
297    }
298
299    async fn post<'a>(
300        &self,
301        web_authn_login_credential_create_request_model: Option<
302            models::WebAuthnLoginCredentialCreateRequestModel,
303        >,
304    ) -> Result<(), Error<PostError>> {
305        let local_var_configuration = &self.configuration;
306
307        let local_var_client = &local_var_configuration.client;
308
309        let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
310        let mut local_var_req_builder =
311            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
312
313        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
314            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
315        };
316        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
317        local_var_req_builder =
318            local_var_req_builder.json(&web_authn_login_credential_create_request_model);
319
320        let local_var_req = local_var_req_builder.build()?;
321        let local_var_resp = local_var_client.execute(local_var_req).await?;
322
323        let local_var_status = local_var_resp.status();
324        let local_var_content = local_var_resp.text().await?;
325
326        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
327            Ok(())
328        } else {
329            let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
330            let local_var_error = ResponseContent {
331                status: local_var_status,
332                content: local_var_content,
333                entity: local_var_entity,
334            };
335            Err(Error::ResponseError(local_var_error))
336        }
337    }
338
339    async fn update_credential<'a>(
340        &self,
341        web_authn_login_credential_update_request_model: Option<
342            models::WebAuthnLoginCredentialUpdateRequestModel,
343        >,
344    ) -> Result<(), Error<UpdateCredentialError>> {
345        let local_var_configuration = &self.configuration;
346
347        let local_var_client = &local_var_configuration.client;
348
349        let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
350        let mut local_var_req_builder =
351            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
352
353        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
354            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
355        };
356        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
357        local_var_req_builder =
358            local_var_req_builder.json(&web_authn_login_credential_update_request_model);
359
360        let local_var_req = local_var_req_builder.build()?;
361        let local_var_resp = local_var_client.execute(local_var_req).await?;
362
363        let local_var_status = local_var_resp.status();
364        let local_var_content = local_var_resp.text().await?;
365
366        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
367            Ok(())
368        } else {
369            let local_var_entity: Option<UpdateCredentialError> =
370                serde_json::from_str(&local_var_content).ok();
371            let local_var_error = ResponseContent {
372                status: local_var_status,
373                content: local_var_content,
374                entity: local_var_entity,
375            };
376            Err(Error::ResponseError(local_var_error))
377        }
378    }
379}
380
381/// struct for typed errors of method [`WebAuthnApi::assertion_options`]
382#[derive(Debug, Clone, Serialize, Deserialize)]
383#[serde(untagged)]
384pub enum AssertionOptionsError {
385    UnknownValue(serde_json::Value),
386}
387/// struct for typed errors of method [`WebAuthnApi::attestation_options`]
388#[derive(Debug, Clone, Serialize, Deserialize)]
389#[serde(untagged)]
390pub enum AttestationOptionsError {
391    UnknownValue(serde_json::Value),
392}
393/// struct for typed errors of method [`WebAuthnApi::delete`]
394#[derive(Debug, Clone, Serialize, Deserialize)]
395#[serde(untagged)]
396pub enum DeleteError {
397    UnknownValue(serde_json::Value),
398}
399/// struct for typed errors of method [`WebAuthnApi::get`]
400#[derive(Debug, Clone, Serialize, Deserialize)]
401#[serde(untagged)]
402pub enum GetError {
403    UnknownValue(serde_json::Value),
404}
405/// struct for typed errors of method [`WebAuthnApi::post`]
406#[derive(Debug, Clone, Serialize, Deserialize)]
407#[serde(untagged)]
408pub enum PostError {
409    UnknownValue(serde_json::Value),
410}
411/// struct for typed errors of method [`WebAuthnApi::update_credential`]
412#[derive(Debug, Clone, Serialize, Deserialize)]
413#[serde(untagged)]
414pub enum UpdateCredentialError {
415    UnknownValue(serde_json::Value),
416}