Skip to main content

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