parent
9bf2cbfb60
commit
d44dea33c9
|
@ -4,6 +4,13 @@ use webauthn_rs::prelude::*;
|
|||
use crate::models::AppState;
|
||||
|
||||
pub async fn start_webauthn_registration(app_state: AppState) -> Result<impl warp::Reply, Infallible> {
|
||||
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()))
|
||||
}
|
||||
|
|
|
@ -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<Mutex<Vec<User>>>;
|
||||
pub type Db = Arc<Mutex<Database>>;
|
||||
|
||||
pub struct Database {
|
||||
pub users: Vec<User>
|
||||
}
|
||||
|
||||
pub struct User {
|
||||
pub uuid: Uuid,
|
||||
pub user_name: String,
|
||||
pub display_name: String
|
||||
pub display_name: String,
|
||||
pub creation_challenge_response: Option<webauthn_rs::prelude::CreationChallengeResponse>,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue