๐ Authentication, MFA & Break-Glass
NextAuth-backed OAuth (Google, Microsoft) with multi-factor enrollment, session heartbeat, and break-glass admin override for emergency clinical access.
๐ Sign-in Methods
- Google OAuth โ primary; enforced for new workspaces.
- Microsoft OAuth โ for organizations on Microsoft 365.
- Telegram Login Widget โ see Telegram.
- Magic-link email โ fallback for users without Google/Microsoft.

๐ก๏ธ Multi-Factor Authentication
- TOTP (authenticator app) โ RFC 6238; 30-second window.
- WebAuthn / Passkey โ preferred; platform authenticator (Touch ID / Windows Hello / Android biometrics).
- Per-workspace policy โ admins can require MFA for any role; clinical roles enforced by default.
- Recovery codes โ 10 single-use codes generated at enrollment.

๐จ Break-Glass Override
For HIPAA-compliant emergency access when primary access path is unavailable.
- Audit-logged on use โ every break-glass invocation writes a row that can NEVER be deleted (append-only audit table).
- Notifies workspace admins immediately via Mail + SMS.
- Time-bounded โ 60-minute access window; automatic re-lockout after.
- Justification required โ admin must enter a reason at break-glass invocation; reason becomes part of the audit record.
๐ Session Heartbeat
- Client pings
/api/v1/session/heartbeatevery 60s while active. - Idle timeout (configurable per workspace; default 15min for clinical roles, 60min for admin).
- Force re-auth on sensitive actions (export, delete, payment) regardless of heartbeat state.
๐๏ธ Architecture
GET /api/v1/auth/session NextAuth session (cookie-backed, JWT)
POST /api/v1/auth/mfa/enroll Begin TOTP / WebAuthn enrollment
POST /api/v1/auth/mfa/verify Verify code at sign-in
POST /api/v1/break-glass Initiate break-glass override (admin-gated)
POST /api/v1/session/heartbeat Idle-keepalive ping| Layer | Tech |
|---|---|
| Session | NextAuth + Postgres adapter; JWT cookies, HttpOnly + Secure + SameSite=Lax |
| MFA storage | Encrypted at rest (AES-256-GCM via lib/oauth-crypto.ts) |
| Audit | withAudit({ module: 'auth' }) on every endpoint; break-glass rows pinned to immutable table |
๐ณ Plans
| Free | Standard | Advanced | Enterprise | |
|---|---|---|---|---|
| OAuth sign-in | โ | โ | โ | โ |
| TOTP MFA | โ | โ | โ | โ |
| WebAuthn / Passkey | โ | โ | โ | โ |
| Workspace-enforced MFA policy | โ | โ | โ | โ |
| Break-glass override | โ | โ | โ | โ |
| SAML / SSO | โ | โ | โ | โ |
| Custom session policy | โ | โ | โ | โ |
See also: portal/docs/security/oauth-token-isolation.md (private) for the full Pattern C OAuth token isolation spec.