Skip to main content

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