Skip to content

Commit

Permalink
469 part deux (#471)
Browse files Browse the repository at this point in the history
* adding WASM back in to tutorial

* fix(tutorial): make the axum tutorial use javascript by default

* fixing tutorial things

* updates
  • Loading branch information
yaleman authored Jan 4, 2025
1 parent 78afc91 commit efa3807
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
20 changes: 8 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version = "0.5.1"
authors = [
"William Brown <[email protected]>",
"Michael Farrell <[email protected]>"
"Michael Farrell <[email protected]>",
]
rust-version = "1.81"
edition = "2021"
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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" }
Expand Down
8 changes: 6 additions & 2 deletions tutorial/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions tutorial/server/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
name = "axum_tutorial"
version = "0.1.0"
edition = "2021"
authors = ["William Brown <[email protected]>, Ben Wishovich <[email protected]>"]
authors = [
"William Brown <[email protected]>, Ben Wishovich <[email protected]>",
]
license = "MPL-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -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"] }
Expand All @@ -22,6 +26,6 @@ tower-http = { version = "0.6", features = ["fs"] }
tower-sessions = "0.13"

[features]
default = ["wasm"]
default = ["javascript"]
wasm = []
javascript = []
13 changes: 3 additions & 10 deletions tutorial/server/axum/README.md
Original file line number Diff line number Diff line change
@@ -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
```
If you want to use the WASM frontend instead, change the features in Cargo.toml.
2 changes: 1 addition & 1 deletion tutorial/server/axum/assets/js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
integrity="sha384-VkKbwLiG7C18stSGuvcw9W0BHk45Ba7P9LJG5c01Yo4BI6qhFoWSa9TQLNA6EOzI"
crossorigin="anonymous">
</script>
<script src="/assets/auth.js" async></script>
<script src="/auth.js" async></script>
</head>
<body>
<p>Welcome to the WebAuthn Server!</p>
Expand Down
16 changes: 8 additions & 8 deletions tutorial/server/axum/assets/wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<title>WebAuthn-rs Tutorial</title>

<script type="module">
import init, { run_app } from './wasm.js';
async function main() {
await init('./wasm_bg.wasm');
run_app();
}
main()
</script>
import init, { run_app } from "./wasm_tutorial.js";
async function main() {
await init("./wasm_tutorial_bg.wasm");
run_app();
}
main();
</script>
</head>
<body>
<p>Welcome to the WebAuthn Server!</p>
</body>
</html>
</html>
6 changes: 4 additions & 2 deletions tutorial/server/axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit efa3807

Please sign in to comment.