Authdog

Rust · axum · actix-web · Rocket · warp · poem

Authentication for axum and every Rust framework

Session middleware, an AuthContext extractor, a require_auth gate, and a logout handler for Rust backends, with dedicated crates for axum, actix-web, Rocket, warp, and poem on a shared authdog-core. Validate Authdog sessions on every request, on the same wire as the Node SDKs.

One layer
Add attach_session as a router layer once and every request carries an AuthContext, usable as an extractor in any handler.
One enforcement point
Layer require_auth on a route and unauthenticated requests are rejected with 401 before your handler runs.
Five crates, one core
axum, actix-web, Rocket, warp, and poem crates share the same public-key, cookie, and userinfo logic in authdog-core.
Validated at startup
Authdog::new parses and checks the public key at boot, so misconfiguration errors immediately.

Wire the middleware

// main.rs
let authdog = Authdog::new(&pk).expect("invalid public key");

let app = Router::new()
  .route("/me", get(me).layer(from_fn(require_auth)))
  .layer(from_fn_with_state(authdog.clone(), attach_session));

Read the session as an extractor

// handlers.rs
async fn me(ctx: AuthContext) -> Json<Value> {
  Json(ctx.user.unwrap_or(Value::Null))
}

Idiomatic per framework, one core

Everything Rust APIs need

Session middleware, an extractor, and a require_auth gate, delivered as a dedicated crate for axum, actix-web, Rocket, warp, or poem.

01

A crate per framework

authdog-axum, authdog-actix, authdog-rocket, authdog-warp, and authdog-poem each wrap the shared authdog-core idiomatically, with middleware and extractors that surface token, user, and is_authenticated.

  • Five framework crates
  • One shared core
02

require_auth gate

Layer require_auth on protected routes and axum responds 401 for unauthenticated requests before your handler runs. This is the security boundary.

  • 401 before your handler
  • Per-route layer
03

Validated at startup

Authdog::new parses and validates the public key once at boot, so a malformed or untrusted key errors immediately instead of at the first request.

  • Fails fast at boot
  • Trusted host enforced
04

Skip the userinfo round-trip

Build with .fetch_user(false) for high-throughput services that validate tokens elsewhere, and supply your own reqwest client when you need to.

  • Opt out of user lookup
  • Bring your own client
06

Same wire as Node

It mirrors @authdog/express and @authdog/fastify on the wire, so one Authdog environment serves your Node and Rust services interchangeably.

  • One environment
  • Node and Rust together
01

Add the crate

Depend on the crate for your framework, e.g. authdog-axum.

02

Layer sessions

Attach attach_session at the router root.

03

Gate routes

Layer require_auth on the routes you protect.

Add auth to your Rust API.

Add the crate for your framework, wire the middleware, and gate your routes with require_auth today. Free to start, with secure defaults built in.