subgraph/graphql/schema/create_auth_service/build_webauthn/
mod.rs1use crate::{configuration::subgraph::auth::ServiceAuth, graphql::schema::ServiceSchema};
2use log::{debug, error, trace};
3use reqwest::Url;
4use webauthn_rs::{Webauthn, WebauthnBuilder};
5
6impl ServiceSchema {
7 pub fn build_webauthn(auth_config: &ServiceAuth) -> Result<Webauthn, async_graphql::Error> {
8 debug!("Building Webauthn");
9
10 let rp_origin = Url::parse(&auth_config.requesting_party_origin).map_err(|e| {
11 error!("Failed to parse requesting party origin: {:?}", e);
12 error!(
13 "Requesting Party Origin: {:?}",
14 &auth_config.requesting_party_origin
15 );
16 async_graphql::Error::new(format!("Failed to parse requesting party origin: {:?}", e))
17 });
18
19 let rp_origin = match rp_origin {
20 Ok(_) => rp_origin.unwrap(),
21 Err(e) => return Err(e),
22 };
23
24 let webauthn_builder = WebauthnBuilder::new(&auth_config.requesting_party, &rp_origin)
25 .map_err(|e| {
26 error!("Failed to build webauthn builder: {:?}", e);
27 trace!("Requesting Party: {:?}", &auth_config.requesting_party);
28 trace!("Requesting Party Origin: {:?}", &rp_origin);
29 async_graphql::Error::new(format!("Failed to build webauthn builder: {:?}", e))
30 });
31
32 let webauthn_builder = match webauthn_builder {
33 Ok(builder) => builder,
34 Err(e) => return Err(e),
35 };
36
37 let webauthn = webauthn_builder
38 .rp_name(&auth_config.requesting_party_name)
39 .build()
40 .map_err(|e| {
41 error!("Failed to build webauthn: {:?}", e);
42 trace!(
43 "Requesting Party Name: {:?}",
44 &auth_config.requesting_party_name
45 );
46 async_graphql::Error::new(format!("Failed to build webauthn: {:?}", e))
47 })?;
48
49 trace!("Webauthn Created: {:?}", webauthn);
50 Ok(webauthn)
51 }
52}