1use 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<AssertionOptionsError>>;
34
35 async fn attestation_options<'a>(
37 &self,
38 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
39 ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error<AttestationOptionsError>>;
40
41 async fn delete<'a>(
43 &self,
44 id: uuid::Uuid,
45 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
46 ) -> Result<(), Error<DeleteError>>;
47
48 async fn get(
50 &self,
51 ) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<GetError>>;
52
53 async fn post<'a>(
55 &self,
56 web_authn_login_credential_create_request_model: Option<
57 models::WebAuthnLoginCredentialCreateRequestModel,
58 >,
59 ) -> Result<models::WebAuthnCredentialResponseModel, Error<PostError>>;
60
61 async fn update_credential<'a>(
63 &self,
64 web_authn_login_credential_update_request_model: Option<
65 models::WebAuthnLoginCredentialUpdateRequestModel,
66 >,
67 ) -> Result<(), Error<UpdateCredentialError>>;
68}
69
70pub struct WebAuthnApiClient {
71 configuration: Arc<configuration::Configuration>,
72}
73
74impl WebAuthnApiClient {
75 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
76 Self { configuration }
77 }
78}
79
80#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
81#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
82impl WebAuthnApi for WebAuthnApiClient {
83 async fn assertion_options<'a>(
84 &self,
85 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
86 ) -> Result<models::WebAuthnLoginAssertionOptionsResponseModel, Error<AssertionOptionsError>>
87 {
88 let local_var_configuration = &self.configuration;
89
90 let local_var_client = &local_var_configuration.client;
91
92 let local_var_uri_str = format!(
93 "{}/webauthn/assertion-options",
94 local_var_configuration.base_path
95 );
96 let mut local_var_req_builder =
97 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
100 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
101
102 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
103 }
104
105 async fn attestation_options<'a>(
106 &self,
107 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
108 ) -> Result<models::WebAuthnCredentialCreateOptionsResponseModel, Error<AttestationOptionsError>>
109 {
110 let local_var_configuration = &self.configuration;
111
112 let local_var_client = &local_var_configuration.client;
113
114 let local_var_uri_str = format!(
115 "{}/webauthn/attestation-options",
116 local_var_configuration.base_path
117 );
118 let mut local_var_req_builder =
119 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
120
121 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
122 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
123
124 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
125 }
126
127 async fn delete<'a>(
128 &self,
129 id: uuid::Uuid,
130 secret_verification_request_model: Option<models::SecretVerificationRequestModel>,
131 ) -> Result<(), Error<DeleteError>> {
132 let local_var_configuration = &self.configuration;
133
134 let local_var_client = &local_var_configuration.client;
135
136 let local_var_uri_str = format!(
137 "{}/webauthn/{id}/delete",
138 local_var_configuration.base_path,
139 id = id
140 );
141 let mut local_var_req_builder =
142 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
143
144 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
145 local_var_req_builder = local_var_req_builder.json(&secret_verification_request_model);
146
147 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
148 }
149
150 async fn get(
151 &self,
152 ) -> Result<models::WebAuthnCredentialResponseModelListResponseModel, Error<GetError>> {
153 let local_var_configuration = &self.configuration;
154
155 let local_var_client = &local_var_configuration.client;
156
157 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
158 let mut local_var_req_builder =
159 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
160
161 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
162
163 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
164 }
165
166 async fn post<'a>(
167 &self,
168 web_authn_login_credential_create_request_model: Option<
169 models::WebAuthnLoginCredentialCreateRequestModel,
170 >,
171 ) -> Result<models::WebAuthnCredentialResponseModel, Error<PostError>> {
172 let local_var_configuration = &self.configuration;
173
174 let local_var_client = &local_var_configuration.client;
175
176 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
177 let mut local_var_req_builder =
178 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
179
180 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
181 local_var_req_builder =
182 local_var_req_builder.json(&web_authn_login_credential_create_request_model);
183
184 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
185 }
186
187 async fn update_credential<'a>(
188 &self,
189 web_authn_login_credential_update_request_model: Option<
190 models::WebAuthnLoginCredentialUpdateRequestModel,
191 >,
192 ) -> Result<(), Error<UpdateCredentialError>> {
193 let local_var_configuration = &self.configuration;
194
195 let local_var_client = &local_var_configuration.client;
196
197 let local_var_uri_str = format!("{}/webauthn", local_var_configuration.base_path);
198 let mut local_var_req_builder =
199 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
200
201 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
202 local_var_req_builder =
203 local_var_req_builder.json(&web_authn_login_credential_update_request_model);
204
205 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
206 }
207}
208
209#[derive(Debug, Clone, Serialize, Deserialize)]
211#[serde(untagged)]
212pub enum AssertionOptionsError {
213 UnknownValue(serde_json::Value),
214}
215#[derive(Debug, Clone, Serialize, Deserialize)]
217#[serde(untagged)]
218pub enum AttestationOptionsError {
219 UnknownValue(serde_json::Value),
220}
221#[derive(Debug, Clone, Serialize, Deserialize)]
223#[serde(untagged)]
224pub enum DeleteError {
225 UnknownValue(serde_json::Value),
226}
227#[derive(Debug, Clone, Serialize, Deserialize)]
229#[serde(untagged)]
230pub enum GetError {
231 UnknownValue(serde_json::Value),
232}
233#[derive(Debug, Clone, Serialize, Deserialize)]
235#[serde(untagged)]
236pub enum PostError {
237 UnknownValue(serde_json::Value),
238}
239#[derive(Debug, Clone, Serialize, Deserialize)]
241#[serde(untagged)]
242pub enum UpdateCredentialError {
243 UnknownValue(serde_json::Value),
244}