bitwarden_api_identity/apis/
accounts_api.rs

1/*
2 * Bitwarden Identity
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: v1
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::{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 AccountsApi: Send + Sync {
29    /// GET /accounts/webauthn/assertion-options
30    async fn get_web_authn_login_assertion_options(
31        &self,
32    ) -> Result<
33        models::WebAuthnLoginAssertionOptionsResponseModel,
34        Error<GetWebAuthnLoginAssertionOptionsError>,
35    >;
36
37    /// POST /accounts/prelogin/password
38    async fn post_password_prelogin<'a>(
39        &self,
40        password_prelogin_request_model: Option<models::PasswordPreloginRequestModel>,
41    ) -> Result<models::PasswordPreloginResponseModel, Error<PostPasswordPreloginError>>;
42
43    /// POST /accounts/register/finish
44    async fn post_register_finish<'a>(
45        &self,
46        register_finish_request_model: Option<models::RegisterFinishRequestModel>,
47    ) -> Result<models::RegisterFinishResponseModel, Error<PostRegisterFinishError>>;
48
49    /// POST /accounts/register/send-verification-email
50    async fn post_register_send_verification_email<'a>(
51        &self,
52        register_send_verification_email_request_model: Option<
53            models::RegisterSendVerificationEmailRequestModel,
54        >,
55    ) -> Result<(), Error<PostRegisterSendVerificationEmailError>>;
56
57    /// POST /accounts/register/verification-email-clicked
58    async fn post_register_verification_email_clicked<'a>(
59        &self,
60        register_verification_email_clicked_request_model: Option<
61            models::RegisterVerificationEmailClickedRequestModel,
62        >,
63    ) -> Result<(), Error<PostRegisterVerificationEmailClickedError>>;
64
65    /// POST /accounts/trial/send-verification-email
66    async fn post_trial_initiation_send_verification_email<'a>(
67        &self,
68        trial_send_verification_email_request_model: Option<
69            models::TrialSendVerificationEmailRequestModel,
70        >,
71    ) -> Result<(), Error<PostTrialInitiationSendVerificationEmailError>>;
72}
73
74pub struct AccountsApiClient {
75    configuration: Arc<configuration::Configuration>,
76}
77
78impl AccountsApiClient {
79    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
80        Self { configuration }
81    }
82}
83
84#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
85#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
86impl AccountsApi for AccountsApiClient {
87    async fn get_web_authn_login_assertion_options(
88        &self,
89    ) -> Result<
90        models::WebAuthnLoginAssertionOptionsResponseModel,
91        Error<GetWebAuthnLoginAssertionOptionsError>,
92    > {
93        let local_var_configuration = &self.configuration;
94
95        let local_var_client = &local_var_configuration.client;
96
97        let local_var_uri_str = format!(
98            "{}/accounts/webauthn/assertion-options",
99            local_var_configuration.base_path
100        );
101        let mut local_var_req_builder =
102            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
103
104        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
105            local_var_req_builder = local_var_req_builder
106                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
107        }
108
109        let local_var_req = local_var_req_builder.build()?;
110        let local_var_resp = local_var_client.execute(local_var_req).await?;
111
112        let local_var_status = local_var_resp.status();
113        let local_var_content_type = local_var_resp
114            .headers()
115            .get("content-type")
116            .and_then(|v| v.to_str().ok())
117            .unwrap_or("application/octet-stream");
118        let local_var_content_type = super::ContentType::from(local_var_content_type);
119        let local_var_content = local_var_resp.text().await?;
120
121        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122            match local_var_content_type {
123                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
124                ContentType::Text => {
125                    return Err(Error::from(serde_json::Error::custom(
126                        "Received `text/plain` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`",
127                    )));
128                }
129                ContentType::Unsupported(local_var_unknown_type) => {
130                    return Err(Error::from(serde_json::Error::custom(format!(
131                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`"
132                    ))));
133                }
134            }
135        } else {
136            let local_var_entity: Option<GetWebAuthnLoginAssertionOptionsError> =
137                serde_json::from_str(&local_var_content).ok();
138            let local_var_error = ResponseContent {
139                status: local_var_status,
140                content: local_var_content,
141                entity: local_var_entity,
142            };
143            Err(Error::ResponseError(local_var_error))
144        }
145    }
146
147    async fn post_password_prelogin<'a>(
148        &self,
149        password_prelogin_request_model: Option<models::PasswordPreloginRequestModel>,
150    ) -> Result<models::PasswordPreloginResponseModel, Error<PostPasswordPreloginError>> {
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            "{}/accounts/prelogin/password",
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        local_var_req_builder = local_var_req_builder.json(&password_prelogin_request_model);
167
168        let local_var_req = local_var_req_builder.build()?;
169        let local_var_resp = local_var_client.execute(local_var_req).await?;
170
171        let local_var_status = local_var_resp.status();
172        let local_var_content_type = local_var_resp
173            .headers()
174            .get("content-type")
175            .and_then(|v| v.to_str().ok())
176            .unwrap_or("application/octet-stream");
177        let local_var_content_type = super::ContentType::from(local_var_content_type);
178        let local_var_content = local_var_resp.text().await?;
179
180        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
181            match local_var_content_type {
182                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
183                ContentType::Text => {
184                    return Err(Error::from(serde_json::Error::custom(
185                        "Received `text/plain` content type response that cannot be converted to `models::PasswordPreloginResponseModel`",
186                    )));
187                }
188                ContentType::Unsupported(local_var_unknown_type) => {
189                    return Err(Error::from(serde_json::Error::custom(format!(
190                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::PasswordPreloginResponseModel`"
191                    ))));
192                }
193            }
194        } else {
195            let local_var_entity: Option<PostPasswordPreloginError> =
196                serde_json::from_str(&local_var_content).ok();
197            let local_var_error = ResponseContent {
198                status: local_var_status,
199                content: local_var_content,
200                entity: local_var_entity,
201            };
202            Err(Error::ResponseError(local_var_error))
203        }
204    }
205
206    async fn post_register_finish<'a>(
207        &self,
208        register_finish_request_model: Option<models::RegisterFinishRequestModel>,
209    ) -> Result<models::RegisterFinishResponseModel, Error<PostRegisterFinishError>> {
210        let local_var_configuration = &self.configuration;
211
212        let local_var_client = &local_var_configuration.client;
213
214        let local_var_uri_str = format!(
215            "{}/accounts/register/finish",
216            local_var_configuration.base_path
217        );
218        let mut local_var_req_builder =
219            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
220
221        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
222            local_var_req_builder = local_var_req_builder
223                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
224        }
225        local_var_req_builder = local_var_req_builder.json(&register_finish_request_model);
226
227        let local_var_req = local_var_req_builder.build()?;
228        let local_var_resp = local_var_client.execute(local_var_req).await?;
229
230        let local_var_status = local_var_resp.status();
231        let local_var_content_type = local_var_resp
232            .headers()
233            .get("content-type")
234            .and_then(|v| v.to_str().ok())
235            .unwrap_or("application/octet-stream");
236        let local_var_content_type = super::ContentType::from(local_var_content_type);
237        let local_var_content = local_var_resp.text().await?;
238
239        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
240            match local_var_content_type {
241                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
242                ContentType::Text => {
243                    return Err(Error::from(serde_json::Error::custom(
244                        "Received `text/plain` content type response that cannot be converted to `models::RegisterFinishResponseModel`",
245                    )));
246                }
247                ContentType::Unsupported(local_var_unknown_type) => {
248                    return Err(Error::from(serde_json::Error::custom(format!(
249                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::RegisterFinishResponseModel`"
250                    ))));
251                }
252            }
253        } else {
254            let local_var_entity: Option<PostRegisterFinishError> =
255                serde_json::from_str(&local_var_content).ok();
256            let local_var_error = ResponseContent {
257                status: local_var_status,
258                content: local_var_content,
259                entity: local_var_entity,
260            };
261            Err(Error::ResponseError(local_var_error))
262        }
263    }
264
265    async fn post_register_send_verification_email<'a>(
266        &self,
267        register_send_verification_email_request_model: Option<
268            models::RegisterSendVerificationEmailRequestModel,
269        >,
270    ) -> Result<(), Error<PostRegisterSendVerificationEmailError>> {
271        let local_var_configuration = &self.configuration;
272
273        let local_var_client = &local_var_configuration.client;
274
275        let local_var_uri_str = format!(
276            "{}/accounts/register/send-verification-email",
277            local_var_configuration.base_path
278        );
279        let mut local_var_req_builder =
280            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
281
282        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
283            local_var_req_builder = local_var_req_builder
284                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
285        }
286        local_var_req_builder =
287            local_var_req_builder.json(&register_send_verification_email_request_model);
288
289        let local_var_req = local_var_req_builder.build()?;
290        let local_var_resp = local_var_client.execute(local_var_req).await?;
291
292        let local_var_status = local_var_resp.status();
293        let local_var_content = local_var_resp.text().await?;
294
295        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
296            Ok(())
297        } else {
298            let local_var_entity: Option<PostRegisterSendVerificationEmailError> =
299                serde_json::from_str(&local_var_content).ok();
300            let local_var_error = ResponseContent {
301                status: local_var_status,
302                content: local_var_content,
303                entity: local_var_entity,
304            };
305            Err(Error::ResponseError(local_var_error))
306        }
307    }
308
309    async fn post_register_verification_email_clicked<'a>(
310        &self,
311        register_verification_email_clicked_request_model: Option<
312            models::RegisterVerificationEmailClickedRequestModel,
313        >,
314    ) -> Result<(), Error<PostRegisterVerificationEmailClickedError>> {
315        let local_var_configuration = &self.configuration;
316
317        let local_var_client = &local_var_configuration.client;
318
319        let local_var_uri_str = format!(
320            "{}/accounts/register/verification-email-clicked",
321            local_var_configuration.base_path
322        );
323        let mut local_var_req_builder =
324            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
325
326        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
327            local_var_req_builder = local_var_req_builder
328                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
329        }
330        local_var_req_builder =
331            local_var_req_builder.json(&register_verification_email_clicked_request_model);
332
333        let local_var_req = local_var_req_builder.build()?;
334        let local_var_resp = local_var_client.execute(local_var_req).await?;
335
336        let local_var_status = local_var_resp.status();
337        let local_var_content = local_var_resp.text().await?;
338
339        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
340            Ok(())
341        } else {
342            let local_var_entity: Option<PostRegisterVerificationEmailClickedError> =
343                serde_json::from_str(&local_var_content).ok();
344            let local_var_error = ResponseContent {
345                status: local_var_status,
346                content: local_var_content,
347                entity: local_var_entity,
348            };
349            Err(Error::ResponseError(local_var_error))
350        }
351    }
352
353    async fn post_trial_initiation_send_verification_email<'a>(
354        &self,
355        trial_send_verification_email_request_model: Option<
356            models::TrialSendVerificationEmailRequestModel,
357        >,
358    ) -> Result<(), Error<PostTrialInitiationSendVerificationEmailError>> {
359        let local_var_configuration = &self.configuration;
360
361        let local_var_client = &local_var_configuration.client;
362
363        let local_var_uri_str = format!(
364            "{}/accounts/trial/send-verification-email",
365            local_var_configuration.base_path
366        );
367        let mut local_var_req_builder =
368            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
369
370        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
371            local_var_req_builder = local_var_req_builder
372                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
373        }
374        local_var_req_builder =
375            local_var_req_builder.json(&trial_send_verification_email_request_model);
376
377        let local_var_req = local_var_req_builder.build()?;
378        let local_var_resp = local_var_client.execute(local_var_req).await?;
379
380        let local_var_status = local_var_resp.status();
381        let local_var_content = local_var_resp.text().await?;
382
383        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
384            Ok(())
385        } else {
386            let local_var_entity: Option<PostTrialInitiationSendVerificationEmailError> =
387                serde_json::from_str(&local_var_content).ok();
388            let local_var_error = ResponseContent {
389                status: local_var_status,
390                content: local_var_content,
391                entity: local_var_entity,
392            };
393            Err(Error::ResponseError(local_var_error))
394        }
395    }
396}
397
398/// struct for typed errors of method [`AccountsApi::get_web_authn_login_assertion_options`]
399#[derive(Debug, Clone, Serialize, Deserialize)]
400#[serde(untagged)]
401pub enum GetWebAuthnLoginAssertionOptionsError {
402    UnknownValue(serde_json::Value),
403}
404/// struct for typed errors of method [`AccountsApi::post_password_prelogin`]
405#[derive(Debug, Clone, Serialize, Deserialize)]
406#[serde(untagged)]
407pub enum PostPasswordPreloginError {
408    UnknownValue(serde_json::Value),
409}
410/// struct for typed errors of method [`AccountsApi::post_register_finish`]
411#[derive(Debug, Clone, Serialize, Deserialize)]
412#[serde(untagged)]
413pub enum PostRegisterFinishError {
414    UnknownValue(serde_json::Value),
415}
416/// struct for typed errors of method [`AccountsApi::post_register_send_verification_email`]
417#[derive(Debug, Clone, Serialize, Deserialize)]
418#[serde(untagged)]
419pub enum PostRegisterSendVerificationEmailError {
420    UnknownValue(serde_json::Value),
421}
422/// struct for typed errors of method [`AccountsApi::post_register_verification_email_clicked`]
423#[derive(Debug, Clone, Serialize, Deserialize)]
424#[serde(untagged)]
425pub enum PostRegisterVerificationEmailClickedError {
426    UnknownValue(serde_json::Value),
427}
428/// struct for typed errors of method [`AccountsApi::post_trial_initiation_send_verification_email`]
429#[derive(Debug, Clone, Serialize, Deserialize)]
430#[serde(untagged)]
431pub enum PostTrialInitiationSendVerificationEmailError {
432    UnknownValue(serde_json::Value),
433}