id_effect_auth
Authentication for id_effect services.
- Passwords (
password):PasswordHasherproduces argon2id PHC strings with the OWASP parameters by default (19 MiB, 2 iterations, 1 lane).verifyhands back an upgraded hash when the stored one used older parameters, andverify_or_dummychecks unknown users against a dummy hash so their response time matches a wrong password's. Hashing runs on the executor's blocking pool. - Sessions (
session):Sessionsover aSessionStore(in-memoryMemorySessionStorefor tests), with idle and absolute timeouts, a fresh id on every login (session fixation), rotation, logout and revoke-all, and a__Host-/Secure/HttpOnly/SameSite=Laxcookie. FeaturepgaddsPgSessionStore: sessions in PostgreSQL overid_effect_sql'sSqlClient, keyed by the SHA-256 of the id (never the id), with an upsertsaveand the schema as a migration (migrations/) orensure_schema(). FeatureaxumaddsSessionLayer, which loads the request's session intoid_effect_axum's request capabilities. - Principals (
principal):AuthPrincipalimplementsid_effect_authz::Principal(id, roles, permissions, claims, tenant) and records theAuthSchemethat authenticated it. - API keys (
apikey):<prefix>_<id>_<secret>keys with 256-bit secrets, stored as SHA-256 digests, found by public id and compared in constant time (ApiKeys,ApiKeyStore). - Basic (
basic):BasicAuthchecks a username and password against aUserLookupwithPasswordHasher::verify_or_dummyand stores upgraded hashes. - JWT (feature
jwt, jsonwebtoken):JwtVerifierchecks HS/RS/PS/ES/EdDSA signatures,iss,aud,exp/nbfwith leeway and required claims, and maps claims to a principal (ClaimMapping, dotted paths such asrealm_access.roles);JwtIssuersigns first-party tokens and publishes its public JWK. FeaturejwksaddsJwksClient, which fetches and caches an identity provider's key set and refetches it, rate-limited, when a token names an unknownkid(key rotation). - Middleware (feature
axum):Authenticatetries session → bearer → API key → Basic (the order is configurable) and installs the principal asid_effect_authz'sCurrentPrincipal. No credential continues anonymously (the route guard decides); an invalid one answers 401 Problem Details withWWW-Authenticatechallenges.
use Exit;
use ;
// Production code uses `PasswordHasher::default()` (OWASP parameters); low cost keeps this fast.
let hasher = new;
let sessions = new;
let Success = hasher.hash.block_on else ;
let Success = hasher.verify_or_dummy.block_on else ;
assert_eq!;
let Success = sessions.login.block_on else ;
let set_cookie = sessions.set_cookie;
assert!;
Feature oidc adds OpenID Connect login (authorization code + PKCE) and feature totp a TOTP
second factor with recovery codes.
Book: Passwords and sessions, Credentials and JWT, OpenID Connect, TOTP.
Tier: platform (ADR 0010 Amendment 5): the Ledger reference app (examples/reference/ledger) depends on it.