Axum App Example
The examples/axum-app crate is a complete, runnable demo showing every authx-rs feature in a single binary.
Running the example
Section titled “Running the example”git clone https://github.com/hamzzy/authx-rscd authx-rscargo run -p axum-appThe server starts at http://localhost:3000.
Open http://localhost:3000/ for a small index page with the seeded demo routes.
What it demonstrates
Section titled “What it demonstrates”MemoryStore(zero config — no DB required)SessionLayer— resolves Identity on every requestRateLimitLayer— 20 requests per minute per IP on/auth/*- CSRF trusted-origin check on all mutating endpoints
- Cookie-based session management (HttpOnly, SameSite=Lax)
- Per-device session listing and revocation
- Brute-force lockout after 5 failures within 15 minutes
RequireAuthextractor protecting/me- OIDC provider endpoints under
/oidc - Seeded public OIDC demo client with
/demo/oidc/login - Seeded federation provider named
selfwith/demo/sso?provider=self
Test it with curl
Section titled “Test it with curl”# Registercurl -s -X POST http://localhost:3000/auth/sign-up \ -H 'Content-Type: application/json' \ -H 'Origin: http://localhost:3000' \ -d '{"email":"alice@example.com","password":"hunter2hunter2"}'
# Sign in — saves session cookie to /tmp/jarcurl -s -c /tmp/jar -X POST http://localhost:3000/auth/sign-in \ -H 'Content-Type: application/json' \ -H 'Origin: http://localhost:3000' \ -d '{"email":"alice@example.com","password":"hunter2hunter2"}'
# Protected routecurl -s -b /tmp/jar http://localhost:3000/me
# List active sessionscurl -s -b /tmp/jar http://localhost:3000/auth/sessions
# Sign out all devicescurl -s -b /tmp/jar -X POST http://localhost:3000/auth/sign-out/all \ -H 'Origin: http://localhost:3000'Health check
Section titled “Health check”curl http://localhost:3000/health# {"status":"ok"}Demo OIDC provider flow
Section titled “Demo OIDC provider flow”After signing in locally, open:
http://localhost:3000/demo/oidc/loginThat route starts an authorization-code flow against authx’s own embedded OIDC provider and renders the resulting token response plus userinfo.
Demo federation flow
Section titled “Demo federation flow”After signing in locally, open:
http://localhost:3000/demo/sso?provider=selfThe example seeds a federation provider called self that points back at the same app’s OIDC provider. This demonstrates the federation plumbing without requiring an external Okta or Azure tenant.