bitwarden_api_identity/apis/
accounts_api.rs1use 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 async fn get_web_authn_login_assertion_options(
31 &self,
32 ) -> Result<
33 models::WebAuthnLoginAssertionOptionsResponseModel,
34 Error<GetWebAuthnLoginAssertionOptionsError>,
35 >;
36
37 async fn post_prelogin<'a>(
39 &self,
40 prelogin_request_model: Option<models::PreloginRequestModel>,
41 ) -> Result<models::PreloginResponseModel, Error<PostPreloginError>>;
42
43 async fn post_register_finish<'a>(
45 &self,
46 register_finish_request_model: Option<models::RegisterFinishRequestModel>,
47 ) -> Result<models::RegisterFinishResponseModel, Error<PostRegisterFinishError>>;
48
49 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 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 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_prelogin<'a>(
148 &self,
149 prelogin_request_model: Option<models::PreloginRequestModel>,
150 ) -> Result<models::PreloginResponseModel, Error<PostPreloginError>> {
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!("{}/accounts/prelogin", local_var_configuration.base_path);
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_user_agent) = local_var_configuration.user_agent {
160 local_var_req_builder = local_var_req_builder
161 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
162 }
163 local_var_req_builder = local_var_req_builder.json(&prelogin_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::PreloginResponseModel`",
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::PreloginResponseModel`"
188 ))));
189 }
190 }
191 } else {
192 let local_var_entity: Option<PostPreloginError> =
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 post_register_finish<'a>(
204 &self,
205 register_finish_request_model: Option<models::RegisterFinishRequestModel>,
206 ) -> Result<models::RegisterFinishResponseModel, Error<PostRegisterFinishError>> {
207 let local_var_configuration = &self.configuration;
208
209 let local_var_client = &local_var_configuration.client;
210
211 let local_var_uri_str = format!(
212 "{}/accounts/register/finish",
213 local_var_configuration.base_path
214 );
215 let mut local_var_req_builder =
216 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
217
218 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
219 local_var_req_builder = local_var_req_builder
220 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
221 }
222 local_var_req_builder = local_var_req_builder.json(®ister_finish_request_model);
223
224 let local_var_req = local_var_req_builder.build()?;
225 let local_var_resp = local_var_client.execute(local_var_req).await?;
226
227 let local_var_status = local_var_resp.status();
228 let local_var_content_type = local_var_resp
229 .headers()
230 .get("content-type")
231 .and_then(|v| v.to_str().ok())
232 .unwrap_or("application/octet-stream");
233 let local_var_content_type = super::ContentType::from(local_var_content_type);
234 let local_var_content = local_var_resp.text().await?;
235
236 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
237 match local_var_content_type {
238 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
239 ContentType::Text => {
240 return Err(Error::from(serde_json::Error::custom(
241 "Received `text/plain` content type response that cannot be converted to `models::RegisterFinishResponseModel`",
242 )));
243 }
244 ContentType::Unsupported(local_var_unknown_type) => {
245 return Err(Error::from(serde_json::Error::custom(format!(
246 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::RegisterFinishResponseModel`"
247 ))));
248 }
249 }
250 } else {
251 let local_var_entity: Option<PostRegisterFinishError> =
252 serde_json::from_str(&local_var_content).ok();
253 let local_var_error = ResponseContent {
254 status: local_var_status,
255 content: local_var_content,
256 entity: local_var_entity,
257 };
258 Err(Error::ResponseError(local_var_error))
259 }
260 }
261
262 async fn post_register_send_verification_email<'a>(
263 &self,
264 register_send_verification_email_request_model: Option<
265 models::RegisterSendVerificationEmailRequestModel,
266 >,
267 ) -> Result<(), Error<PostRegisterSendVerificationEmailError>> {
268 let local_var_configuration = &self.configuration;
269
270 let local_var_client = &local_var_configuration.client;
271
272 let local_var_uri_str = format!(
273 "{}/accounts/register/send-verification-email",
274 local_var_configuration.base_path
275 );
276 let mut local_var_req_builder =
277 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
278
279 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
280 local_var_req_builder = local_var_req_builder
281 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
282 }
283 local_var_req_builder =
284 local_var_req_builder.json(®ister_send_verification_email_request_model);
285
286 let local_var_req = local_var_req_builder.build()?;
287 let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289 let local_var_status = local_var_resp.status();
290 let local_var_content = local_var_resp.text().await?;
291
292 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
293 Ok(())
294 } else {
295 let local_var_entity: Option<PostRegisterSendVerificationEmailError> =
296 serde_json::from_str(&local_var_content).ok();
297 let local_var_error = ResponseContent {
298 status: local_var_status,
299 content: local_var_content,
300 entity: local_var_entity,
301 };
302 Err(Error::ResponseError(local_var_error))
303 }
304 }
305
306 async fn post_register_verification_email_clicked<'a>(
307 &self,
308 register_verification_email_clicked_request_model: Option<
309 models::RegisterVerificationEmailClickedRequestModel,
310 >,
311 ) -> Result<(), Error<PostRegisterVerificationEmailClickedError>> {
312 let local_var_configuration = &self.configuration;
313
314 let local_var_client = &local_var_configuration.client;
315
316 let local_var_uri_str = format!(
317 "{}/accounts/register/verification-email-clicked",
318 local_var_configuration.base_path
319 );
320 let mut local_var_req_builder =
321 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
322
323 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
324 local_var_req_builder = local_var_req_builder
325 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
326 }
327 local_var_req_builder =
328 local_var_req_builder.json(®ister_verification_email_clicked_request_model);
329
330 let local_var_req = local_var_req_builder.build()?;
331 let local_var_resp = local_var_client.execute(local_var_req).await?;
332
333 let local_var_status = local_var_resp.status();
334 let local_var_content = local_var_resp.text().await?;
335
336 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
337 Ok(())
338 } else {
339 let local_var_entity: Option<PostRegisterVerificationEmailClickedError> =
340 serde_json::from_str(&local_var_content).ok();
341 let local_var_error = ResponseContent {
342 status: local_var_status,
343 content: local_var_content,
344 entity: local_var_entity,
345 };
346 Err(Error::ResponseError(local_var_error))
347 }
348 }
349
350 async fn post_trial_initiation_send_verification_email<'a>(
351 &self,
352 trial_send_verification_email_request_model: Option<
353 models::TrialSendVerificationEmailRequestModel,
354 >,
355 ) -> Result<(), Error<PostTrialInitiationSendVerificationEmailError>> {
356 let local_var_configuration = &self.configuration;
357
358 let local_var_client = &local_var_configuration.client;
359
360 let local_var_uri_str = format!(
361 "{}/accounts/trial/send-verification-email",
362 local_var_configuration.base_path
363 );
364 let mut local_var_req_builder =
365 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
366
367 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
368 local_var_req_builder = local_var_req_builder
369 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
370 }
371 local_var_req_builder =
372 local_var_req_builder.json(&trial_send_verification_email_request_model);
373
374 let local_var_req = local_var_req_builder.build()?;
375 let local_var_resp = local_var_client.execute(local_var_req).await?;
376
377 let local_var_status = local_var_resp.status();
378 let local_var_content = local_var_resp.text().await?;
379
380 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
381 Ok(())
382 } else {
383 let local_var_entity: Option<PostTrialInitiationSendVerificationEmailError> =
384 serde_json::from_str(&local_var_content).ok();
385 let local_var_error = ResponseContent {
386 status: local_var_status,
387 content: local_var_content,
388 entity: local_var_entity,
389 };
390 Err(Error::ResponseError(local_var_error))
391 }
392 }
393}
394
395#[derive(Debug, Clone, Serialize, Deserialize)]
397#[serde(untagged)]
398pub enum GetWebAuthnLoginAssertionOptionsError {
399 UnknownValue(serde_json::Value),
400}
401#[derive(Debug, Clone, Serialize, Deserialize)]
403#[serde(untagged)]
404pub enum PostPreloginError {
405 UnknownValue(serde_json::Value),
406}
407#[derive(Debug, Clone, Serialize, Deserialize)]
409#[serde(untagged)]
410pub enum PostRegisterFinishError {
411 UnknownValue(serde_json::Value),
412}
413#[derive(Debug, Clone, Serialize, Deserialize)]
415#[serde(untagged)]
416pub enum PostRegisterSendVerificationEmailError {
417 UnknownValue(serde_json::Value),
418}
419#[derive(Debug, Clone, Serialize, Deserialize)]
421#[serde(untagged)]
422pub enum PostRegisterVerificationEmailClickedError {
423 UnknownValue(serde_json::Value),
424}
425#[derive(Debug, Clone, Serialize, Deserialize)]
427#[serde(untagged)]
428pub enum PostTrialInitiationSendVerificationEmailError {
429 UnknownValue(serde_json::Value),
430}