crates.io ↗

iet-auth-basic-axum

integration adapter official

Registers a JSON login endpoint over the password-auth contracts.

CoreFeaturesIntegrationsStacksTooling
Used byno framework crate yetexamples/htmx-starter
iet-auth-basic-axumadapterPassword-login REST adapter
Depends oniet-corecontractiet-authcontractiet-http-axumcontract

How to use it

Registers a JSON password-login endpoint on a iet_http_axum::RestApi: it authenticates via iet_auth::Authenticate<PasswordCredentials> and returns a bearer token from iet_auth::TokenIssuer. Pair it with any credential verifier and token provider; the route is mounted as the auth.basic module.

rust
// examples/htmx-starter/servers/web/tests/framework_auth_rest.rs
fn compose<L: iet_http_axum::RateLimit>(api: RestApi<u32, L>) -> Router {
    // `sessions` is an Arc<Sessions<..>>: it implements Authenticate and TokenIssuer.
    let api = iet_auth_basic_axum::register(
        api,
        "/login",
        Arc::new(Passwords), // impl iet_auth::Authenticate<PasswordCredentials>
        sessions.clone(),    // impl iet_auth::TokenIssuer
    )
    .unwrap();
    // ...
    api.finish(42)
}
  • Responses are Cache-Control: no-store; the module registers a fixed 10/60s rate-limit policy.
  • Invalid bodies/credentials are mapped to validated HTTP errors without echoing secrets.

How it works

register mounts the path as the named auth.basic module with an inline rate-limit policy and stores (authenticator, issuer) as router state; the handler validates LoginRequest, calls Authenticate<PasswordCredentials>, then TokenIssuer::issue and returns a JSON TokenResponse.

flowchart LR
  Req["POST path"] --> Module["auth.basic module"]
  Module --> Login["api login"]
  Login --> Val["ValidatedJson LoginRequest"]
  Val --> Auth["Authenticate PasswordCredentials"]
  Auth --> Iss["TokenIssuer issue"]
  Iss --> Resp["TokenResponse no-store"]

What it implements

  • Concrete mechanism; see the public API below.

What's inside

Modules

  • src/api.rs
  • src/dto.rs
  • src/injector.rs
  • src/lib.rs

Public API

dto

  • struct LoginRequest

injector

  • pub fn register<S, A, I, L>( api: RestApi<S, L>, path: &str, authentication: Arc<A>, issuer: Arc<I>, ) -> AppResult<RestApi<S, L>> where L: iet_http_axum::RateLimit, — Registers password login at path; other auth capabilities remain opt-in.

Impl map

  • Validate for LoginRequest

Depends on

External crates: axum, serde

Used by

  • No other framework crate depends on it directly.

In this repository

  • examples/htmx-starter

Source: crates/integrations/iet-auth-basic-axum