bitwarden_api_api/apis/
web_authn_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 WebAuthnApi: Send + Sync {
29 async fn assertion_options<'a>(
31 &self,
32 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
33 ) -> Result<models::WebAuthnLoginAssertionOptionsResponseModel, Error>;
34
35 async fn attestation_options<'a>(
37 &self,
38 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
39 ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error>;
40
41 async fn delete<'a>(
43 &self,
44 id: uuid::Uuid,
45 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
46 ) -> Result<(), Error>;
47
48 async fn get(&self) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error>;
50
51 async fn post<'a>(
53 &self,
54 web_authn_login_credential_create_request_model: Option<
55 models::WebAuthnLoginCredentialCreateRequestModel,
56 >,
57 ) -> Result<models::WebAuthnCredentialResponseModel, Error>;
58
59 async fn update_credential<'a>(
61 &self,
62 web_authn_login_credential_update_request_model: Option<
63 models::WebAuthnLoginCredentialUpdateRequestModel,
64 >,
65 ) -> Result<(), Error>;
66}
67
68pub struct WebAuthnApiClient {
69 configuration: Arc<configuration::Configuration>,
70}
71
72impl WebAuthnApiClient {
73 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
74 Self { configuration }
75 }
76}
77
78#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
79#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
80impl WebAuthnApi for WebAuthnApiClient {
81 async fn assertion_options<'a>(
82 &self,
83 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
84 ) -> Result<models::WebAuthnLoginAssertionOptionsResponseModel, Error> {
85 let local_var_configuration = &self.configuration;
86
87 let local_var_client = &local_var_configuration.client;
88
89 let local_var_uri_str = format!(
90 "{}/webauthn/assertion-options",
91 local_var_configuration.base_path
92 );
93 let mut local_var_req_builder =
94 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
95
96 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
97 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
98
99 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
100 }
101
102 async fn attestation_options<'a>(
103 &self,
104 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
105 ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error> {
106 let local_var_configuration = &self.configuration;
107
108 let local_var_client = &local_var_configuration.client;
109
110 let local_var_uri_str = format!(
111 "{}/webauthn/attestation-options",
112 local_var_configuration.base_path
113 );
114 let mut local_var_req_builder =
115 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
116
117 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
118 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
119
120 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
121 }
122
123 async fn delete<'a>(
124 &self,
125 id: uuid::Uuid,
126 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
127 ) -> Result<(), Error> {
128 let local_var_configuration = &self.configuration;
129
130 let local_var_client = &local_var_configuration.client;
131
132 let local_var_uri_str = format!(
133 "{}/webauthn/{id}/delete",
134 local_var_configuration.base_path,
135 id = id
136 );
137 let mut local_var_req_builder =
138 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
139
140 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
141 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
142
143 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
144 }
145
146 async fn get(&self) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error> {
147 let local_var_configuration = &self.configuration;
148
149 let local_var_client = &local_var_configuration.client;
150
151 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
152 let mut local_var_req_builder =
153 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
154
155 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
156
157 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
158 }
159
160 async fn post<'a>(
161 &self,
162 web_authn_login_credential_create_request_model: Option<
163 models::WebAuthnLoginCredentialCreateRequestModel,
164 >,
165 ) -> Result<models::WebAuthnCredentialResponseModel, Error> {
166 let local_var_configuration = &self.configuration;
167
168 let local_var_client = &local_var_configuration.client;
169
170 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
171 let mut local_var_req_builder =
172 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
173
174 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
175 local_var_req_builder =
176 local_var_req_builder.json(&web_authn_login_credential_create_request_model);
177
178 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
179 }
180
181 async fn update_credential<'a>(
182 &self,
183 web_authn_login_credential_update_request_model: Option<
184 models::WebAuthnLoginCredentialUpdateRequestModel,
185 >,
186 ) -> Result<(), Error> {
187 let local_var_configuration = &self.configuration;
188
189 let local_var_client = &local_var_configuration.client;
190
191 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
192 let mut local_var_req_builder =
193 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
194
195 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
196 local_var_req_builder =
197 local_var_req_builder.json(&web_authn_login_credential_update_request_model);
198
199 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
200 }
201}