1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! 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 a [`SessionStore`] (in-memory
//! [`MemorySessionStore`] for tests), with idle and absolute timeouts, a fresh id on every
//! login, rotation, logout and revoke-all, and a hardened cookie. Feature `pg` adds
//! `PgSessionStore`: sessions in PostgreSQL over `id_effect_sql`, keyed by the SHA-256 of the
//! id, with the crate's `migrations/`. Feature `axum` adds `SessionLayer`, which loads the
//! request's session into `id_effect_axum`'s request capabilities.
//! - [`principal`] — [`AuthPrincipal`], the `id_effect_authz::Principal` every credential check
//! yields, tagged with its [`AuthScheme`]; [`AuthError`] says why a credential was rejected.
//! - [`apikey`] — [`ApiKeys`]: random keys stored as SHA-256 digests in an [`ApiKeyStore`],
//! found by public id and compared in constant time.
//! - [`basic`] — [`BasicAuth`]: username and password against a [`UserLookup`], with
//! [`PasswordHasher::verify_or_dummy`] for unknown users.
//! - `jwt` (feature `jwt`) — `JwtVerifier` / `JwtIssuer`: HS/RS/PS/ES/EdDSA tokens with issuer,
//! audience, expiry and required-claim checks and a claim → roles/permissions mapping.
//! Feature `jwks` adds `JwksClient`: the identity provider's key set, cached and refetched
//! (rate-limited) when a token names an unknown `kid`.
//! - `middleware` (feature `axum`) — `Authenticate`: session → bearer → API key → Basic, in a
//! configurable order, installing the principal as `id_effect_authz::CurrentPrincipal`.
//! Missing credentials continue anonymously; invalid ones answer 401 Problem Details.
//! - `oidc` (feature `oidc`) — `OidcClient`: OpenID Connect discovery, authorization code +
//! PKCE (S256), ID tokens verified over the provider's JWKS (`iss`, `aud`, `exp`, `nonce`,
//! `azp`) and mapped with a `ClaimMapping`; `OidcRoutes`: `/auth/oidc/{login,callback,logout}`
//! with state, nonce and code verifier in a server-side flow session, login through
//! `Sessions::login`, and RP-initiated logout. Implements id_effect_platform's `OAuthClient`.
//! - `totp` (feature `totp`) — `Totp`: RFC 6238 enrolment (160-bit secret, `otpauth://` URI)
//! and verification with ±1 step of skew on a `WallClock` and replay protection through a
//! `TotpStepStore`; `RecoveryCodes`: single-use codes stored as argon2id hashes;
//! `Totp::step_up` marks the session after a second factor, `with_mfa_claims` and
//! `require_mfa` carry it to `id_effect_authz` policies.
//!
//! [`PasswordHasher`] and [`Sessions`] are capabilities with a [`Layer`](id_effect::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"));
//! ```
pub use ;
pub use ;
pub use AuthError;
pub use JwksClient;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SessionLayer;
pub use ;
pub use ;
pub use ;
/// Compiles and runs the README's code block as a doctest.
;