bitwarden_api_identity/apis/
accounts_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum AccountsPreloginPostError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum AccountsRegisterFinishPostError {
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum AccountsRegisterPostError {
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum AccountsRegisterSendVerificationEmailPostError {
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum AccountsRegisterVerificationEmailClickedPostError {
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum AccountsTrialSendVerificationEmailPostError {
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum AccountsWebauthnAssertionOptionsGetError {
63 UnknownValue(serde_json::Value),
64}
65
66pub async fn accounts_prelogin_post(
67 configuration: &configuration::Configuration,
68 prelogin_request_model: Option<models::PreloginRequestModel>,
69) -> Result<models::PreloginResponseModel, Error<AccountsPreloginPostError>> {
70 let p_prelogin_request_model = prelogin_request_model;
72
73 let uri_str = format!("{}/accounts/prelogin", configuration.base_path);
74 let mut req_builder = configuration
75 .client
76 .request(reqwest::Method::POST, &uri_str);
77
78 if let Some(ref user_agent) = configuration.user_agent {
79 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
80 }
81 req_builder = req_builder.json(&p_prelogin_request_model);
82
83 let req = req_builder.build()?;
84 let resp = configuration.client.execute(req).await?;
85
86 let status = resp.status();
87 let content_type = resp
88 .headers()
89 .get("content-type")
90 .and_then(|v| v.to_str().ok())
91 .unwrap_or("application/octet-stream");
92 let content_type = super::ContentType::from(content_type);
93
94 if !status.is_client_error() && !status.is_server_error() {
95 let content = resp.text().await?;
96 match content_type {
97 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PreloginResponseModel`"))),
99 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PreloginResponseModel`")))),
100 }
101 } else {
102 let content = resp.text().await?;
103 let entity: Option<AccountsPreloginPostError> = serde_json::from_str(&content).ok();
104 Err(Error::ResponseError(ResponseContent {
105 status,
106 content,
107 entity,
108 }))
109 }
110}
111
112pub async fn accounts_register_finish_post(
113 configuration: &configuration::Configuration,
114 register_finish_request_model: Option<models::RegisterFinishRequestModel>,
115) -> Result<models::RegisterResponseModel, Error<AccountsRegisterFinishPostError>> {
116 let p_register_finish_request_model = register_finish_request_model;
118
119 let uri_str = format!("{}/accounts/register/finish", configuration.base_path);
120 let mut req_builder = configuration
121 .client
122 .request(reqwest::Method::POST, &uri_str);
123
124 if let Some(ref user_agent) = configuration.user_agent {
125 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126 }
127 req_builder = req_builder.json(&p_register_finish_request_model);
128
129 let req = req_builder.build()?;
130 let resp = configuration.client.execute(req).await?;
131
132 let status = resp.status();
133 let content_type = resp
134 .headers()
135 .get("content-type")
136 .and_then(|v| v.to_str().ok())
137 .unwrap_or("application/octet-stream");
138 let content_type = super::ContentType::from(content_type);
139
140 if !status.is_client_error() && !status.is_server_error() {
141 let content = resp.text().await?;
142 match content_type {
143 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
144 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegisterResponseModel`"))),
145 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegisterResponseModel`")))),
146 }
147 } else {
148 let content = resp.text().await?;
149 let entity: Option<AccountsRegisterFinishPostError> = serde_json::from_str(&content).ok();
150 Err(Error::ResponseError(ResponseContent {
151 status,
152 content,
153 entity,
154 }))
155 }
156}
157
158pub async fn accounts_register_post(
159 configuration: &configuration::Configuration,
160 register_request_model: Option<models::RegisterRequestModel>,
161) -> Result<models::RegisterResponseModel, Error<AccountsRegisterPostError>> {
162 let p_register_request_model = register_request_model;
164
165 let uri_str = format!("{}/accounts/register", configuration.base_path);
166 let mut req_builder = configuration
167 .client
168 .request(reqwest::Method::POST, &uri_str);
169
170 if let Some(ref user_agent) = configuration.user_agent {
171 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172 }
173 req_builder = req_builder.json(&p_register_request_model);
174
175 let req = req_builder.build()?;
176 let resp = configuration.client.execute(req).await?;
177
178 let status = resp.status();
179 let content_type = resp
180 .headers()
181 .get("content-type")
182 .and_then(|v| v.to_str().ok())
183 .unwrap_or("application/octet-stream");
184 let content_type = super::ContentType::from(content_type);
185
186 if !status.is_client_error() && !status.is_server_error() {
187 let content = resp.text().await?;
188 match content_type {
189 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
190 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegisterResponseModel`"))),
191 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegisterResponseModel`")))),
192 }
193 } else {
194 let content = resp.text().await?;
195 let entity: Option<AccountsRegisterPostError> = serde_json::from_str(&content).ok();
196 Err(Error::ResponseError(ResponseContent {
197 status,
198 content,
199 entity,
200 }))
201 }
202}
203
204pub async fn accounts_register_send_verification_email_post(
205 configuration: &configuration::Configuration,
206 register_send_verification_email_request_model: Option<
207 models::RegisterSendVerificationEmailRequestModel,
208 >,
209) -> Result<(), Error<AccountsRegisterSendVerificationEmailPostError>> {
210 let p_register_send_verification_email_request_model =
212 register_send_verification_email_request_model;
213
214 let uri_str = format!(
215 "{}/accounts/register/send-verification-email",
216 configuration.base_path
217 );
218 let mut req_builder = configuration
219 .client
220 .request(reqwest::Method::POST, &uri_str);
221
222 if let Some(ref user_agent) = configuration.user_agent {
223 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224 }
225 req_builder = req_builder.json(&p_register_send_verification_email_request_model);
226
227 let req = req_builder.build()?;
228 let resp = configuration.client.execute(req).await?;
229
230 let status = resp.status();
231
232 if !status.is_client_error() && !status.is_server_error() {
233 Ok(())
234 } else {
235 let content = resp.text().await?;
236 let entity: Option<AccountsRegisterSendVerificationEmailPostError> =
237 serde_json::from_str(&content).ok();
238 Err(Error::ResponseError(ResponseContent {
239 status,
240 content,
241 entity,
242 }))
243 }
244}
245
246pub async fn accounts_register_verification_email_clicked_post(
247 configuration: &configuration::Configuration,
248 register_verification_email_clicked_request_model: Option<
249 models::RegisterVerificationEmailClickedRequestModel,
250 >,
251) -> Result<(), Error<AccountsRegisterVerificationEmailClickedPostError>> {
252 let p_register_verification_email_clicked_request_model =
254 register_verification_email_clicked_request_model;
255
256 let uri_str = format!(
257 "{}/accounts/register/verification-email-clicked",
258 configuration.base_path
259 );
260 let mut req_builder = configuration
261 .client
262 .request(reqwest::Method::POST, &uri_str);
263
264 if let Some(ref user_agent) = configuration.user_agent {
265 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
266 }
267 req_builder = req_builder.json(&p_register_verification_email_clicked_request_model);
268
269 let req = req_builder.build()?;
270 let resp = configuration.client.execute(req).await?;
271
272 let status = resp.status();
273
274 if !status.is_client_error() && !status.is_server_error() {
275 Ok(())
276 } else {
277 let content = resp.text().await?;
278 let entity: Option<AccountsRegisterVerificationEmailClickedPostError> =
279 serde_json::from_str(&content).ok();
280 Err(Error::ResponseError(ResponseContent {
281 status,
282 content,
283 entity,
284 }))
285 }
286}
287
288pub async fn accounts_trial_send_verification_email_post(
289 configuration: &configuration::Configuration,
290 trial_send_verification_email_request_model: Option<
291 models::TrialSendVerificationEmailRequestModel,
292 >,
293) -> Result<(), Error<AccountsTrialSendVerificationEmailPostError>> {
294 let p_trial_send_verification_email_request_model = trial_send_verification_email_request_model;
296
297 let uri_str = format!(
298 "{}/accounts/trial/send-verification-email",
299 configuration.base_path
300 );
301 let mut req_builder = configuration
302 .client
303 .request(reqwest::Method::POST, &uri_str);
304
305 if let Some(ref user_agent) = configuration.user_agent {
306 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
307 }
308 req_builder = req_builder.json(&p_trial_send_verification_email_request_model);
309
310 let req = req_builder.build()?;
311 let resp = configuration.client.execute(req).await?;
312
313 let status = resp.status();
314
315 if !status.is_client_error() && !status.is_server_error() {
316 Ok(())
317 } else {
318 let content = resp.text().await?;
319 let entity: Option<AccountsTrialSendVerificationEmailPostError> =
320 serde_json::from_str(&content).ok();
321 Err(Error::ResponseError(ResponseContent {
322 status,
323 content,
324 entity,
325 }))
326 }
327}
328
329pub async fn accounts_webauthn_assertion_options_get(
330 configuration: &configuration::Configuration,
331) -> Result<
332 models::WebAuthnLoginAssertionOptionsResponseModel,
333 Error<AccountsWebauthnAssertionOptionsGetError>,
334> {
335 let uri_str = format!(
336 "{}/accounts/webauthn/assertion-options",
337 configuration.base_path
338 );
339 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
340
341 if let Some(ref user_agent) = configuration.user_agent {
342 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
343 }
344
345 let req = req_builder.build()?;
346 let resp = configuration.client.execute(req).await?;
347
348 let status = resp.status();
349 let content_type = resp
350 .headers()
351 .get("content-type")
352 .and_then(|v| v.to_str().ok())
353 .unwrap_or("application/octet-stream");
354 let content_type = super::ContentType::from(content_type);
355
356 if !status.is_client_error() && !status.is_server_error() {
357 let content = resp.text().await?;
358 match content_type {
359 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
360 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`"))),
361 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`")))),
362 }
363 } else {
364 let content = resp.text().await?;
365 let entity: Option<AccountsWebauthnAssertionOptionsGetError> =
366 serde_json::from_str(&content).ok();
367 Err(Error::ResponseError(ResponseContent {
368 status,
369 content,
370 entity,
371 }))
372 }
373}