Authentication
bloom_auth_server provides server-side authentication primitives modeled on djangors-auth, designed as the backend partner to BloomAuth<U> on Flutter clients.
Server-Side Authentication Primitives
Authentication state is configured globally through BLOOM_AUTH_SECRET loaded by BloomEnv. The package provides constant-time password verification, sliding-window throttling, and JWT token issuance out of the box:
Password Hashing & Session Tokens
OpenBSD BCrypt Hashing
Uses hashPassword(password, cost: 12) with configurable rounds (4,096 iterations).
When a requested account is not found, dummyVerifyPassword(password) executes uniform verification cycles to defeat timing attacks and account enumeration.
Signed Session JWTs
issueSessionToken() generates RFC 7519 JWT bearer tokens signed with HMAC-SHA256.
Tokens include domain-separated token_type: 'session' claims to prevent token substitution attacks.
Rate Limiting & Account Lockout
AuthRateLimiter combines sliding-window rate limiting (InMemoryRateLimiter) and consecutive-failure account lockout (InMemoryLockoutManager) with fail-closed security semantics:
verifyAllowed(identifier)— ThrowsAccountLockedExceptionorRateLimitExceptionif thresholds are exceeded.recordFailure(identifier)— Increments attempt count and triggers account lockout after consecutive failed attempts.recordSuccess(identifier)— Clears failure streaks upon successful authentication.
Route Protection with BloomAuthMiddleware
Attach BloomAuthMiddleware to routes or routers to enforce bearer token validation, decode claims, and attach user information to req.auth and req.authUserId:
Hash-Bound Password Reset
generatePasswordResetToken() creates single-purpose tokens bound cryptographically to the user's current password hash. Whenever the user's password changes, all outstanding reset tokens are invalidated immediately without requiring database revocation tables.