diff --git a/Cargo.toml b/Cargo.toml index b9d8f66f..47247fa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ version = "0.5.1" authors = [ "William Brown ", - "Michael Farrell " + "Michael Farrell ", ] rust-version = "1.81" edition = "2021" @@ -33,6 +33,7 @@ members = [ "tutorial/server/tide", "tutorial/server/axum", "tutorial/server/actix_web", + "tutorial/wasm", # Attestatation struct format "attestation-ca", # Fido MDS tools @@ -51,10 +52,7 @@ members = [ ] # Due to --cfg=web_sys_unstable_apis -exclude = [ - "compat_tester/webauthn-rs-demo-wasm", - "tutorial/wasm", -] +exclude = ["compat_tester/webauthn-rs-demo-wasm", "tutorial/wasm"] [workspace.dependencies] # These are in release/dependency order. @@ -81,19 +79,17 @@ hex = "0.4.3" http = "^0.2.9" http-body = "1.0.1" http-body-util = "0.1.2" -hyper = { version = "1.5.1", default-features = false, features = [ - "http1", -] } -hyper-util = { version = "0.1.10", features = [ - "tokio", -] } +hyper = { version = "1.5.1", default-features = false, features = ["http1"] } +hyper-util = { version = "0.1.10", features = ["tokio"] } nom = "7.1" peg = "0.8.1" openssl = "^0.10.56" rand = "0.8" rand_chacha = "0.3.1" -reqwest = { version = "0.12", default-features = false, features = [ "rustls-tls-native-roots" ] } +reqwest = { version = "0.12", default-features = false, features = [ + "rustls-tls-native-roots", +] } serde = { version = "^1.0.141", features = ["derive"] } serde_cbor_2 = { version = "0.12.0-dev" } diff --git a/tutorial/Makefile b/tutorial/Makefile index 594a4505..644c6673 100644 --- a/tutorial/Makefile +++ b/tutorial/Makefile @@ -3,19 +3,23 @@ help: @grep -E -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' +.PHONY: wasm wasm: ## build the WASM parts wasm: cd wasm && ./build.sh +.PHONY: actix actix: ## Build the WASM parts and run the actix server actix: wasm cd server/actix_web && cargo run -axum: ## Build and run the axum server +.PHONY: axum +axum: ## Build and run the axum server, builds the WASM parts regardless. axum: + cd server/axum && ./build_wasm.sh cd server/axum && cargo run - +.PHONY: tide tide: ## Build and run the tide server tide: wasm cd server/tide && cargo run diff --git a/tutorial/server/axum/Cargo.toml b/tutorial/server/axum/Cargo.toml index 78fd166c..8880ebab 100644 --- a/tutorial/server/axum/Cargo.toml +++ b/tutorial/server/axum/Cargo.toml @@ -2,7 +2,9 @@ name = "axum_tutorial" version = "0.1.0" edition = "2021" -authors = ["William Brown , Ben Wishovich "] +authors = [ + "William Brown , Ben Wishovich ", +] license = "MPL-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -11,7 +13,9 @@ license = "MPL-2.0" tracing.workspace = true tracing-subscriber.workspace = true serde.workspace = true -webauthn-rs = { workspace = true, features = ["danger-allow-state-serialisation"] } +webauthn-rs = { workspace = true, features = [ + "danger-allow-state-serialisation", +] } axum = { version = "0.7" } tokio = { workspace = true, features = ["full"] } uuid = { workspace = true, features = ["v4"] } @@ -22,6 +26,6 @@ tower-http = { version = "0.6", features = ["fs"] } tower-sessions = "0.13" [features] -default = ["wasm"] +default = ["javascript"] wasm = [] javascript = [] diff --git a/tutorial/server/axum/README.md b/tutorial/server/axum/README.md index 24c899c6..69178f45 100644 --- a/tutorial/server/axum/README.md +++ b/tutorial/server/axum/README.md @@ -1,14 +1,7 @@ -## Axum Server +# Axum Server This demonstrates using Axum as the backend. -By default, it serves the WASM front-end ([located here](https://github.com/kanidm/webauthn-rs/tree/master/tutorial/wasm "located here")). -This needs to be built first by running the below ([wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) is required). -```sh -./build_wasm.sh -``` +By default, it serves the Javascript front-end. -If you want to use the HTML/Javascript front-end instead, run the following command. -```sh -cargo run --no-default-features --features javascript -``` \ No newline at end of file +If you want to use the WASM frontend instead, change the features in Cargo.toml. diff --git a/tutorial/server/axum/assets/js/index.html b/tutorial/server/axum/assets/js/index.html index 9f8e6320..357cff81 100644 --- a/tutorial/server/axum/assets/js/index.html +++ b/tutorial/server/axum/assets/js/index.html @@ -9,7 +9,7 @@ integrity="sha384-VkKbwLiG7C18stSGuvcw9W0BHk45Ba7P9LJG5c01Yo4BI6qhFoWSa9TQLNA6EOzI" crossorigin="anonymous"> - +

Welcome to the WebAuthn Server!

diff --git a/tutorial/server/axum/assets/wasm/index.html b/tutorial/server/axum/assets/wasm/index.html index 48e19e9f..ae0c612c 100644 --- a/tutorial/server/axum/assets/wasm/index.html +++ b/tutorial/server/axum/assets/wasm/index.html @@ -6,15 +6,15 @@ WebAuthn-rs Tutorial + import init, { run_app } from "./wasm_tutorial.js"; + async function main() { + await init("./wasm_tutorial_bg.wasm"); + run_app(); + } + main(); +

Welcome to the WebAuthn Server!

- \ No newline at end of file + diff --git a/tutorial/server/axum/src/main.rs b/tutorial/server/axum/src/main.rs index c77f44e3..38b9c0af 100644 --- a/tutorial/server/axum/src/main.rs +++ b/tutorial/server/axum/src/main.rs @@ -1,5 +1,7 @@ use axum::{extract::Extension, http::StatusCode, response::IntoResponse, routing::post, Router}; -use std::{net::SocketAddr, path::PathBuf}; +use std::net::SocketAddr; +#[cfg(feature = "wasm")] +use std::path::PathBuf; use tower_sessions::{ cookie::{time::Duration, SameSite}, Expiry, MemoryStore, SessionManagerLayer, @@ -72,7 +74,7 @@ async fn main() { #[cfg(feature = "javascript")] let app = Router::new() .merge(app) - .nest_service("/assets", tower_http::services::ServeDir::new("assets/js")); + .nest_service("/", tower_http::services::ServeDir::new("assets/js")); // run our app with hyper // `axum::Server` is a re-export of `hyper::Server`