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