bitwarden_api_api/apis/
web_authn_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{Deserialize, Serialize};
13
14use super::{configuration, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`webauthn_assertion_options_post`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum WebauthnAssertionOptionsPostError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`webauthn_attestation_options_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum WebauthnAttestationOptionsPostError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`webauthn_get`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum WebauthnGetError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`webauthn_id_delete_post`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum WebauthnIdDeletePostError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`webauthn_post`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum WebauthnPostError {
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`webauthn_put`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum WebauthnPutError {
56    UnknownValue(serde_json::Value),
57}
58
59pub async fn webauthn_assertion_options_post(
60    configuration: &configuration::Configuration,
61    secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
62) -> Result<
63    models::WebAuthnLoginAssertionOptionsResponseModel,
64    Error<WebauthnAssertionOptionsPostError>,
65> {
66    let local_var_configuration = configuration;
67
68    let local_var_client = &local_var_configuration.client;
69
70    let local_var_uri_str = format!(
71        "{}/webauthn/assertion-options",
72        local_var_configuration.base_path
73    );
74    let mut local_var_req_builder =
75        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
76
77    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78        local_var_req_builder =
79            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
80    }
81    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
82        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
83    };
84    local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
85
86    let local_var_req = local_var_req_builder.build()?;
87    let local_var_resp = local_var_client.execute(local_var_req).await?;
88
89    let local_var_status = local_var_resp.status();
90    let local_var_content = local_var_resp.text().await?;
91
92    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
93        serde_json::from_str(&local_var_content).map_err(Error::from)
94    } else {
95        let local_var_entity: Option<WebauthnAssertionOptionsPostError> =
96            serde_json::from_str(&local_var_content).ok();
97        let local_var_error = ResponseContent {
98            status: local_var_status,
99            content: local_var_content,
100            entity: local_var_entity,
101        };
102        Err(Error::ResponseError(local_var_error))
103    }
104}
105
106pub async fn webauthn_attestation_options_post(
107    configuration: &configuration::Configuration,
108    secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
109) -> Result<
110    models::WebAuthnCredentialCreateOptionsResponseModel,
111    Error<WebauthnAttestationOptionsPostError>,
112> {
113    let local_var_configuration = configuration;
114
115    let local_var_client = &local_var_configuration.client;
116
117    let local_var_uri_str = format!(
118        "{}/webauthn/attestation-options",
119        local_var_configuration.base_path
120    );
121    let mut local_var_req_builder =
122        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
123
124    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
125        local_var_req_builder =
126            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
127    }
128    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
129        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
130    };
131    local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
132
133    let local_var_req = local_var_req_builder.build()?;
134    let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136    let local_var_status = local_var_resp.status();
137    let local_var_content = local_var_resp.text().await?;
138
139    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
140        serde_json::from_str(&local_var_content).map_err(Error::from)
141    } else {
142        let local_var_entity: Option<WebauthnAttestationOptionsPostError> =
143            serde_json::from_str(&local_var_content).ok();
144        let local_var_error = ResponseContent {
145            status: local_var_status,
146            content: local_var_content,
147            entity: local_var_entity,
148        };
149        Err(Error::ResponseError(local_var_error))
150    }
151}
152
153pub async fn webauthn_get(
154    configuration: &configuration::Configuration,
155) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<WebauthnGetError>> {
156    let local_var_configuration = configuration;
157
158    let local_var_client = &local_var_configuration.client;
159
160    let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
161    let mut local_var_req_builder =
162        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
163
164    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
165        local_var_req_builder =
166            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
167    }
168    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
169        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
170    };
171
172    let local_var_req = local_var_req_builder.build()?;
173    let local_var_resp = local_var_client.execute(local_var_req).await?;
174
175    let local_var_status = local_var_resp.status();
176    let local_var_content = local_var_resp.text().await?;
177
178    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
179        serde_json::from_str(&local_var_content).map_err(Error::from)
180    } else {
181        let local_var_entity: Option<WebauthnGetError> =
182            serde_json::from_str(&local_var_content).ok();
183        let local_var_error = ResponseContent {
184            status: local_var_status,
185            content: local_var_content,
186            entity: local_var_entity,
187        };
188        Err(Error::ResponseError(local_var_error))
189    }
190}
191
192pub async fn webauthn_id_delete_post(
193    configuration: &configuration::Configuration,
194    id: uuid::Uuid,
195    secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
196) -> Result<(), Error<WebauthnIdDeletePostError>> {
197    let local_var_configuration = configuration;
198
199    let local_var_client = &local_var_configuration.client;
200
201    let local_var_uri_str = format!(
202        "{}/webauthn/{id}/delete",
203        local_var_configuration.base_path,
204        id = crate::apis::urlencode(id.to_string())
205    );
206    let mut local_var_req_builder =
207        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
208
209    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
210        local_var_req_builder =
211            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
212    }
213    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
214        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
215    };
216    local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
217
218    let local_var_req = local_var_req_builder.build()?;
219    let local_var_resp = local_var_client.execute(local_var_req).await?;
220
221    let local_var_status = local_var_resp.status();
222    let local_var_content = local_var_resp.text().await?;
223
224    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
225        Ok(())
226    } else {
227        let local_var_entity: Option<WebauthnIdDeletePostError> =
228            serde_json::from_str(&local_var_content).ok();
229        let local_var_error = ResponseContent {
230            status: local_var_status,
231            content: local_var_content,
232            entity: local_var_entity,
233        };
234        Err(Error::ResponseError(local_var_error))
235    }
236}
237
238pub async fn webauthn_post(
239    configuration: &configuration::Configuration,
240    web_authn_login_credential_create_request_model: Option<
241        models::WebAuthnLoginCredentialCreateRequestModel,
242    >,
243) -> Result<(), Error<WebauthnPostError>> {
244    let local_var_configuration = configuration;
245
246    let local_var_client = &local_var_configuration.client;
247
248    let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
249    let mut local_var_req_builder =
250        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
251
252    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
253        local_var_req_builder =
254            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
255    }
256    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
257        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
258    };
259    local_var_req_builder =
260        local_var_req_builder.json(&web_authn_login_credential_create_request_model);
261
262    let local_var_req = local_var_req_builder.build()?;
263    let local_var_resp = local_var_client.execute(local_var_req).await?;
264
265    let local_var_status = local_var_resp.status();
266    let local_var_content = local_var_resp.text().await?;
267
268    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
269        Ok(())
270    } else {
271        let local_var_entity: Option<WebauthnPostError> =
272            serde_json::from_str(&local_var_content).ok();
273        let local_var_error = ResponseContent {
274            status: local_var_status,
275            content: local_var_content,
276            entity: local_var_entity,
277        };
278        Err(Error::ResponseError(local_var_error))
279    }
280}
281
282pub async fn webauthn_put(
283    configuration: &configuration::Configuration,
284    web_authn_login_credential_update_request_model: Option<
285        models::WebAuthnLoginCredentialUpdateRequestModel,
286    >,
287) -> Result<(), Error<WebauthnPutError>> {
288    let local_var_configuration = configuration;
289
290    let local_var_client = &local_var_configuration.client;
291
292    let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
293    let mut local_var_req_builder =
294        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
295
296    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
297        local_var_req_builder =
298            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
299    }
300    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
301        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
302    };
303    local_var_req_builder =
304        local_var_req_builder.json(&web_authn_login_credential_update_request_model);
305
306    let local_var_req = local_var_req_builder.build()?;
307    let local_var_resp = local_var_client.execute(local_var_req).await?;
308
309    let local_var_status = local_var_resp.status();
310    let local_var_content = local_var_resp.text().await?;
311
312    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
313        Ok(())
314    } else {
315        let local_var_entity: Option<WebauthnPutError> =
316            serde_json::from_str(&local_var_content).ok();
317        let local_var_error = ResponseContent {
318            status: local_var_status,
319            content: local_var_content,
320            entity: local_var_entity,
321        };
322        Err(Error::ResponseError(local_var_error))
323    }
324}