diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index edffba2..952e08f 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -4,6 +4,13 @@ use webauthn_rs::prelude::*; use crate::models::AppState; pub async fn start_webauthn_registration(app_state: AppState) -> Result { - app_state.webauthn.start_passkey_registration(); + let mut db = app_state.db.lock().await; + // TODO: query the user + let mut user = db.users.first_mut().unwrap(); + + let (creation_challenge_response, passkey_registration) = app_state.webauthn.start_passkey_registration(user.uuid, &user.user_name, &user.display_name, None).unwrap(); + + user.creation_challenge_response = Some(creation_challenge_response); + Ok(warp::reply::json(&"hello".to_string())) } diff --git a/src/models/mod.rs b/src/models/mod.rs index 23de6d6..a32d0a5 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1,15 +1,22 @@ use url::Url; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc}; + +use tokio::sync::{Mutex}; use webauthn_rs::prelude::Uuid; use webauthn_rs::{Webauthn, WebauthnBuilder}; -pub type Db = Arc>>; +pub type Db = Arc>; + +pub struct Database { + pub users: Vec +} pub struct User { pub uuid: Uuid, pub user_name: String, - pub display_name: String + pub display_name: String, + pub creation_challenge_response: Option, } pub struct AppState { @@ -24,7 +31,19 @@ impl AppState { let builder = WebauthnBuilder::new(rp, &rp_origin).expect("Invalid configuration"); let builder = builder.rp_name("LocalHost"); let webauthn = Arc::new(builder.build().expect("Invalid configuration")); - let db: Db = Arc::new(Mutex::new(Vec::new())); - AppState {webauthn, db} + let user: User = User { + uuid: Uuid::new_v4(), + user_name: "felix".to_string(), + display_name: "FĂ©lix".to_string(), + creation_challenge_response: None, + }; + let db: Db = Arc::new(Mutex::new(Database { + users: Vec::from([user]) + })); + + AppState { + webauthn, + db, + } } }