webauthn
: Define code structure
This commit is contained in:
parent
9e0439b2a3
commit
3c42f974da
9 changed files with 68 additions and 0 deletions
|
@ -22,6 +22,7 @@ serde = { version = "1.0.215", features = ["derive"] }
|
|||
serde_json = "1.0.132"
|
||||
tokio = { version = "1.41.1", features = ["macros", "net", "rt-multi-thread"] }
|
||||
mediatype = { version = "0.19.18", features = ["serde"] }
|
||||
webauthn-rs = "0.5.1"
|
||||
|
||||
[lints.clippy]
|
||||
tabs-in-doc-comments = "allow"
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
micronfig::config!(
|
||||
ACRATE_WEBAUTHN_BIND_ADDRESS: String > std::net::SocketAddr,
|
||||
ACRATE_WEBAUTHN_RELYING_PARTY_ID: String,
|
||||
ACRATE_WEBAUTHN_RELYING_PARTY_ORIGIN: String > webauthn_rs::prelude::Url,
|
||||
ACRATE_WEBAUTHN_RELYING_PARTY_NAME: String,
|
||||
);
|
||||
|
|
32
acrate_webauthn/src/ext.rs
Normal file
32
acrate_webauthn/src/ext.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use std::sync::Arc;
|
||||
use axum::Extension;
|
||||
use webauthn_rs::{Webauthn, WebauthnBuilder};
|
||||
|
||||
pub type ExtWebAuthn = Extension<Arc<Webauthn>>;
|
||||
|
||||
pub fn ext_webauthn() -> ExtWebAuthn {
|
||||
log::debug!("Creating ExtWebAuthn...");
|
||||
|
||||
let rp_id = crate::config::ACRATE_WEBAUTHN_RELYING_PARTY_ID().as_str();
|
||||
log::trace!("Relying party ID is set to: {rp_id:?}");
|
||||
|
||||
let rp_origin = crate::config::ACRATE_WEBAUTHN_RELYING_PARTY_ORIGIN();
|
||||
log::trace!("Relying party origin is set to: {rp_origin:?}");
|
||||
|
||||
let rp_name = crate::config::ACRATE_WEBAUTHN_RELYING_PARTY_NAME();
|
||||
log::trace!("Relying party name is set to: {rp_name:?}");
|
||||
|
||||
log::trace!("Creating WebAuthnBuilder with the given parameters...");
|
||||
let builder = WebauthnBuilder::new(rp_id, rp_origin)
|
||||
.expect("Relying party origin must be a subdomain of relying party ID")
|
||||
.rp_name(rp_name);
|
||||
|
||||
log::trace!("Running builder...");
|
||||
let webauthn = builder.build().unwrap();
|
||||
|
||||
log::trace!("Wrapping in an Arc...");
|
||||
let arc = Arc::new(webauthn);
|
||||
|
||||
log::trace!("Wrapping in an Extension...");
|
||||
Extension(arc)
|
||||
}
|
|
@ -3,6 +3,7 @@ use acrate_utils::web_server;
|
|||
|
||||
mod config;
|
||||
mod routes;
|
||||
mod ext;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
@ -11,6 +12,9 @@ async fn main() {
|
|||
templates: [],
|
||||
routes: {
|
||||
"/.healthcheck" => get(routes::healthcheck::handler)
|
||||
},
|
||||
layers: {
|
||||
ext::ext_webauthn()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
0
acrate_webauthn/src/routes/authentication_finish.rs
Normal file
0
acrate_webauthn/src/routes/authentication_finish.rs
Normal file
0
acrate_webauthn/src/routes/authentication_start.rs
Normal file
0
acrate_webauthn/src/routes/authentication_start.rs
Normal file
|
@ -1 +1,5 @@
|
|||
pub mod healthcheck;
|
||||
mod registration_start;
|
||||
mod registration_finish;
|
||||
mod authentication_start;
|
||||
mod authentication_finish;
|
||||
|
|
0
acrate_webauthn/src/routes/registration_finish.rs
Normal file
0
acrate_webauthn/src/routes/registration_finish.rs
Normal file
24
acrate_webauthn/src/routes/registration_start.rs
Normal file
24
acrate_webauthn/src/routes/registration_start.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use axum::Extension;
|
||||
use axum::http::StatusCode;
|
||||
use acrate_database::connect::connect_async;
|
||||
use crate::ext::ExtWebAuthn;
|
||||
|
||||
pub async fn handler(
|
||||
Extension(webauthn): ExtWebAuthn,
|
||||
) -> Result<StatusCode, StatusCode> {
|
||||
log::debug!("Handling a registration start request!");
|
||||
|
||||
log::trace!("Connecting to the database...");
|
||||
let _conn = connect_async()
|
||||
.await
|
||||
.map_err(|_| StatusCode::BAD_GATEWAY)?;
|
||||
|
||||
let result = webauthn.start_passkey_registration(
|
||||
user_id,
|
||||
user_name,
|
||||
user_display_name,
|
||||
exclude_credentials,
|
||||
);
|
||||
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
Loading…
Add table
Reference in a new issue