Expand description
Authentication for id_effect services.
password—PasswordHasher: argon2id PHC hashes with the OWASP parameters by default, verification that hands back an upgraded hash when the parameters changed, and a dummy verification so an unknown user costs the same time as a wrong password. Hashing runs on the executor’s blocking pool.session—Sessions: server-side sessions behind aSessionStore(in-memoryMemorySessionStorefor tests), with idle and absolute timeouts, a fresh id on every login, rotation, logout and revoke-all, and a hardened cookie. FeaturepgaddsPgSessionStore: sessions in PostgreSQL overid_effect_sql, keyed by the SHA-256 of the id, with the crate’smigrations/. FeatureaxumaddsSessionLayer, which loads the request’s session intoid_effect_axum’s request capabilities.principal—AuthPrincipal, theid_effect_authz::Principalevery credential check yields, tagged with itsAuthScheme;AuthErrorsays why a credential was rejected.apikey—ApiKeys: random keys stored as SHA-256 digests in anApiKeyStore, found by public id and compared in constant time.basic—BasicAuth: username and password against aUserLookup, withPasswordHasher::verify_or_dummyfor unknown users.throttle—LoginThrottle: exponential backoff after failed logins per account and per client address, checked before hashing (on by default inBasicAuth), over aThrottleStore; featurepgaddsPgThrottleStore, shared by every instance.jwt(featurejwt) —JwtVerifier/JwtIssuer: HS/RS/PS/ES/EdDSA tokens with issuer, audience, expiry and required-claim checks and a claim → roles/permissions mapping. FeaturejwksaddsJwksClient: the identity provider’s key set, cached and refetched (rate-limited) when a token names an unknownkid.middleware(featureaxum) —Authenticate: session → bearer → API key → Basic, in a configurable order, installing the principal asid_effect_authz::CurrentPrincipal. Missing credentials continue anonymously; invalid ones answer 401 Problem Details.oidc(featureoidc) —OidcClient: OpenID Connect discovery, authorization code + PKCE (S256), ID tokens verified over the provider’s JWKS (iss,aud,exp,nonce,azp) and mapped with aClaimMapping;OidcRoutes:/auth/oidc/{login,callback,logout}with state, nonce and code verifier in a server-side flow session, login throughSessions::login, and RP-initiated logout. Implements id_effect_platform’sOAuthClient.totp(featuretotp) —Totp: RFC 6238 enrolment (160-bit secret,otpauth://URI) and verification with ±1 step of skew on aWallClockand replay protection through aTotpStepStore(PgTotpStepStorewith featurepg);RecoveryCodes: single-use codes stored as argon2id hashes;Totp::step_upmarks the session after a second factor,with_mfa_claimsandrequire_mfacarry it toid_effect_authzpolicies.account(featureaccounts) —Accounts: registration, email verification and forgot / reset password with single-use expiring tokens stored as SHA-256 digests (PgAccountTokenStore), a forgot-password answer that does not reveal whether the account exists, and a reset that revokes the account’s sessions; the mails go through anAccountNotifier(id_effect_mail’s featureauth), never a job queue.AccountRoutesserves them under/auth.
PasswordHasher and Sessions are capabilities with a Layer, like
the rest of the platform crates; the credential checks are cheap-to-clone values whose methods
return effects, held by the middleware or a handler.
Tier platform (ADR 0010 Amendment 5): the Ledger reference app under
examples/reference/ depends on it.
use id_effect::Exit;
use id_effect_auth::{
MemorySessionStore, PasswordHasher, PasswordParams, SessionConfig, Sessions, Verification,
};
let hasher = PasswordHasher::new(PasswordParams::new(64, 1, 1).unwrap()); // low cost for docs
let sessions = Sessions::new(MemorySessionStore::new(), SessionConfig::default());
let Exit::Success(stored) = hasher.hash("s3cret").block_on() else { panic!() };
let Exit::Success(check) = hasher.verify_or_dummy("s3cret", Some(&stored)).block_on() else {
panic!()
};
assert_eq!(check, Verification::Valid);
let Exit::Success(session) = sessions.login("user-1", None).block_on() else { panic!() };
assert!(sessions.set_cookie(&session).contains("HttpOnly"));Re-exports§
pub use account::Account;pub use account::AccountError;pub use account::AccountMail;pub use account::AccountNotifier;pub use account::AccountRoutes;pub use account::AccountStore;pub use account::AccountToken;pub use account::AccountTokenStore;pub use account::Accounts;pub use account::AccountsConfig;pub use account::MemoryAccountNotifier;pub use account::MemoryAccountStore;pub use account::MemoryAccountTokenStore;pub use account::PgAccountTokenStore;pub use account::TokenKind;pub use account::TokenRecord;pub use apikey::ApiKey;pub use apikey::ApiKeyRecord;pub use apikey::ApiKeyStore;pub use apikey::ApiKeys;pub use apikey::MemoryApiKeyStore;pub use basic::BasicAuth;pub use basic::MemoryUsers;pub use basic::UserCredentials;pub use basic::UserLookup;pub use basic::basic_credentials;pub use basic::basic_header;pub use jwks::JwksClient;pub use jwt::ClaimMapping;pub use jwt::JwtIssuer;pub use jwt::JwtKey;pub use jwt::JwtVerifier;pub use middleware::Authenticate;pub use middleware::AuthenticateService;pub use oidc::OidcClient;pub use oidc::OidcConfig;pub use oidc::OidcError;pub use oidc::OidcRoutes;pub use password::MAX_PASSWORD_LEN;pub use password::Password;pub use password::PasswordError;pub use password::PasswordHash;pub use password::PasswordHasher;pub use password::PasswordHasherEnv;pub use password::PasswordParams;pub use password::Verification;pub use principal::AuthPrincipal;pub use principal::AuthScheme;pub use session::SessionLayer;pub use session::CookieConfig;pub use session::MemorySessionStore;pub use session::SameSite;pub use session::Session;pub use session::SessionConfig;pub use session::SessionError;pub use session::SessionId;pub use session::SessionStore;pub use session::SessionStoreService;pub use session::Sessions;pub use session::PgSessionStore;pub use session::pg_session_store_layer;pub use throttle::PgThrottleStore;pub use throttle::Failures;pub use throttle::LoginThrottle;pub use throttle::MEMORY_THROTTLE_STORE_POSTURE;pub use throttle::MemoryThrottleStore;pub use throttle::ThrottleStore;pub use totp::PgTotpStepStore;pub use totp::MemoryTotpStepStore;pub use totp::RecoveryCodes;pub use totp::Totp;pub use totp::TotpConfig;pub use totp::TotpError;pub use totp::TotpSecret;pub use totp::TotpStepStore;pub use totp::TotpVerification;
Modules§
- account
- Account flows (feature
accounts): registration, email verification, and forgot / reset password with single-use expiring tokens. - apikey
- API keys: random secrets stored as SHA-256 digests, found by a public id and compared in constant time.
- basic
- HTTP Basic credentials: a username and password checked against a
UserLookupwith aPasswordHasher. - jwks
JwksClient(featurejwks): an issuer’s JSON Web Key Set, fetched over HTTP and cached, refetched when a token names a key it does not know.- jwt
- JSON Web Tokens (feature
jwt):JwtVerifierturns a bearer token into anAuthPrincipal,JwtIssuersigns first-party tokens. - middleware
Authenticate(featureaxum): declarative credential middleware that turns a request’s session cookie, bearer JWT, API key or Basic credentials into its principal.- oidc
- OpenID Connect login (feature
oidc):OidcClientspeaks to the identity provider,OidcRoutesmounts the browser flow on an axum router. - password
- Password hashing: argon2id PHC strings, verification that reports when a stored hash should be upgraded, and a dummy verification for unknown users.
- principal
AuthPrincipal: the principal a credential authenticates, as anid_effect_authz::Principal.- session
- Server-side sessions: opaque random ids in a cookie, session state in a
SessionStore. - throttle
LoginThrottle: exponential backoff after failed logins, per account and per client address, checked before any password hashing.- totp
- TOTP second factor (RFC 6238, over totp-rs): enrolment, verification on the executor’s clock with replay protection, argon2-hashed recovery codes, and an MFA step-up marker on the session.