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 AccountsRegisterSendVerificationEmailPostError {
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum AccountsRegisterVerificationEmailClickedPostError {
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum AccountsTrialSendVerificationEmailPostError {
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum AccountsWebauthnAssertionOptionsGetError {
56 UnknownValue(serde_json::Value),
57}
58
59pub async fn accounts_prelogin_post(
60 configuration: &configuration::Configuration,
61 prelogin_request_model: Option<models::PreloginRequestModel>,
62) -> Result<models::PreloginResponseModel, Error<AccountsPreloginPostError>> {
63 let p_prelogin_request_model = prelogin_request_model;
65
66 let uri_str = format!("{}/accounts/prelogin", configuration.base_path);
67 let mut req_builder = configuration
68 .client
69 .request(reqwest::Method::POST, &uri_str);
70
71 if let Some(ref user_agent) = configuration.user_agent {
72 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
73 }
74 req_builder = req_builder.json(&p_prelogin_request_model);
75
76 let req = req_builder.build()?;
77 let resp = configuration.client.execute(req).await?;
78
79 let status = resp.status();
80 let content_type = resp
81 .headers()
82 .get("content-type")
83 .and_then(|v| v.to_str().ok())
84 .unwrap_or("application/octet-stream");
85 let content_type = super::ContentType::from(content_type);
86
87 if !status.is_client_error() && !status.is_server_error() {
88 let content = resp.text().await?;
89 match content_type {
90 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PreloginResponseModel`"))),
92 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`")))),
93 }
94 } else {
95 let content = resp.text().await?;
96 let entity: Option<AccountsPreloginPostError> = serde_json::from_str(&content).ok();
97 Err(Error::ResponseError(ResponseContent {
98 status,
99 content,
100 entity,
101 }))
102 }
103}
104
105pub async fn accounts_register_finish_post(
106 configuration: &configuration::Configuration,
107 register_finish_request_model: Option<models::RegisterFinishRequestModel>,
108) -> Result<models::RegisterFinishResponseModel, Error<AccountsRegisterFinishPostError>> {
109 let p_register_finish_request_model = register_finish_request_model;
111
112 let uri_str = format!("{}/accounts/register/finish", configuration.base_path);
113 let mut req_builder = configuration
114 .client
115 .request(reqwest::Method::POST, &uri_str);
116
117 if let Some(ref user_agent) = configuration.user_agent {
118 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119 }
120 req_builder = req_builder.json(&p_register_finish_request_model);
121
122 let req = req_builder.build()?;
123 let resp = configuration.client.execute(req).await?;
124
125 let status = resp.status();
126 let content_type = resp
127 .headers()
128 .get("content-type")
129 .and_then(|v| v.to_str().ok())
130 .unwrap_or("application/octet-stream");
131 let content_type = super::ContentType::from(content_type);
132
133 if !status.is_client_error() && !status.is_server_error() {
134 let content = resp.text().await?;
135 match content_type {
136 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
137 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegisterFinishResponseModel`"))),
138 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::RegisterFinishResponseModel`")))),
139 }
140 } else {
141 let content = resp.text().await?;
142 let entity: Option<AccountsRegisterFinishPostError> = serde_json::from_str(&content).ok();
143 Err(Error::ResponseError(ResponseContent {
144 status,
145 content,
146 entity,
147 }))
148 }
149}
150
151pub async fn accounts_register_send_verification_email_post(
152 configuration: &configuration::Configuration,
153 register_send_verification_email_request_model: Option<
154 models::RegisterSendVerificationEmailRequestModel,
155 >,
156) -> Result<(), Error<AccountsRegisterSendVerificationEmailPostError>> {
157 let p_register_send_verification_email_request_model =
159 register_send_verification_email_request_model;
160
161 let uri_str = format!(
162 "{}/accounts/register/send-verification-email",
163 configuration.base_path
164 );
165 let mut req_builder = configuration
166 .client
167 .request(reqwest::Method::POST, &uri_str);
168
169 if let Some(ref user_agent) = configuration.user_agent {
170 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171 }
172 req_builder = req_builder.json(&p_register_send_verification_email_request_model);
173
174 let req = req_builder.build()?;
175 let resp = configuration.client.execute(req).await?;
176
177 let status = resp.status();
178
179 if !status.is_client_error() && !status.is_server_error() {
180 Ok(())
181 } else {
182 let content = resp.text().await?;
183 let entity: Option<AccountsRegisterSendVerificationEmailPostError> =
184 serde_json::from_str(&content).ok();
185 Err(Error::ResponseError(ResponseContent {
186 status,
187 content,
188 entity,
189 }))
190 }
191}
192
193pub async fn accounts_register_verification_email_clicked_post(
194 configuration: &configuration::Configuration,
195 register_verification_email_clicked_request_model: Option<
196 models::RegisterVerificationEmailClickedRequestModel,
197 >,
198) -> Result<(), Error<AccountsRegisterVerificationEmailClickedPostError>> {
199 let p_register_verification_email_clicked_request_model =
201 register_verification_email_clicked_request_model;
202
203 let uri_str = format!(
204 "{}/accounts/register/verification-email-clicked",
205 configuration.base_path
206 );
207 let mut req_builder = configuration
208 .client
209 .request(reqwest::Method::POST, &uri_str);
210
211 if let Some(ref user_agent) = configuration.user_agent {
212 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213 }
214 req_builder = req_builder.json(&p_register_verification_email_clicked_request_model);
215
216 let req = req_builder.build()?;
217 let resp = configuration.client.execute(req).await?;
218
219 let status = resp.status();
220
221 if !status.is_client_error() && !status.is_server_error() {
222 Ok(())
223 } else {
224 let content = resp.text().await?;
225 let entity: Option<AccountsRegisterVerificationEmailClickedPostError> =
226 serde_json::from_str(&content).ok();
227 Err(Error::ResponseError(ResponseContent {
228 status,
229 content,
230 entity,
231 }))
232 }
233}
234
235pub async fn accounts_trial_send_verification_email_post(
236 configuration: &configuration::Configuration,
237 trial_send_verification_email_request_model: Option<
238 models::TrialSendVerificationEmailRequestModel,
239 >,
240) -> Result<(), Error<AccountsTrialSendVerificationEmailPostError>> {
241 let p_trial_send_verification_email_request_model = trial_send_verification_email_request_model;
243
244 let uri_str = format!(
245 "{}/accounts/trial/send-verification-email",
246 configuration.base_path
247 );
248 let mut req_builder = configuration
249 .client
250 .request(reqwest::Method::POST, &uri_str);
251
252 if let Some(ref user_agent) = configuration.user_agent {
253 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
254 }
255 req_builder = req_builder.json(&p_trial_send_verification_email_request_model);
256
257 let req = req_builder.build()?;
258 let resp = configuration.client.execute(req).await?;
259
260 let status = resp.status();
261
262 if !status.is_client_error() && !status.is_server_error() {
263 Ok(())
264 } else {
265 let content = resp.text().await?;
266 let entity: Option<AccountsTrialSendVerificationEmailPostError> =
267 serde_json::from_str(&content).ok();
268 Err(Error::ResponseError(ResponseContent {
269 status,
270 content,
271 entity,
272 }))
273 }
274}
275
276pub async fn accounts_webauthn_assertion_options_get(
277 configuration: &configuration::Configuration,
278) -> Result<
279 models::WebAuthnLoginAssertionOptionsResponseModel,
280 Error<AccountsWebauthnAssertionOptionsGetError>,
281> {
282 let uri_str = format!(
283 "{}/accounts/webauthn/assertion-options",
284 configuration.base_path
285 );
286 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
287
288 if let Some(ref user_agent) = configuration.user_agent {
289 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
290 }
291
292 let req = req_builder.build()?;
293 let resp = configuration.client.execute(req).await?;
294
295 let status = resp.status();
296 let content_type = resp
297 .headers()
298 .get("content-type")
299 .and_then(|v| v.to_str().ok())
300 .unwrap_or("application/octet-stream");
301 let content_type = super::ContentType::from(content_type);
302
303 if !status.is_client_error() && !status.is_server_error() {
304 let content = resp.text().await?;
305 match content_type {
306 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
307 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WebAuthnLoginAssertionOptionsResponseModel`"))),
308 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`")))),
309 }
310 } else {
311 let content = resp.text().await?;
312 let entity: Option<AccountsWebauthnAssertionOptionsGetError> =
313 serde_json::from_str(&content).ok();
314 Err(Error::ResponseError(ResponseContent {
315 status,
316 content,
317 entity,
318 }))
319 }
320}