@rapidrest/auth
v1.0.0
Published
A library for implementing a complete authentication server in RapidREST.
Readme
RapidREST: Authentication Library
A library for implementing a complete authentication server with RapidREST. It provides the data models, persistence adapters, and HTTP routes needed to register and authenticate users via password, TOTP, OTP (email/SMS), WebAuthn passkeys, FIDO2 hardware security keys, multi-factor authentication, and OpenID Connect / OAuth 2.0. Using this library you can stand up a fully featured authorization server by writing configuration and a handful of one-line route classes.
For complete documentation please visit RapidREST.dev.
Features
Authentication Strategies:
BasicStrategy- Simple id and password authenticationFIDO2Strategy- FIDO2/WebAuthn hardware based authentication (e.g. YubiKey)MFAStrategy- Simple id and password + 2FA authentication [fido2|otp|recovery-code|totp]OIDCStrategy- OAuth 2.0 & OpenID Connect authenticationOTPStrategy- One-Time Password (OTP) authentication (e.g. email, sms)PasskeyStrategy- WebAuthn based passkey authenticationTOTPStrategy- RFC 6238 Time-Based One Time Password authentication (e.g. Google Authenticator, etc.)
Security Features
- Rate limiting on every credential-verification endpoint, layered per-identifier and per-source-IP (reverse-proxy aware)
- MFA recovery/backup codes as a first-class secondary authentication method
- Account elevation (
@RequiresElevation) for step-up re-verification before sensitive actions - Session revocation ("log out everywhere") that invalidates every outstanding refresh token for an account
- Optional TOTP secret encryption at rest (AES-256-GCM)
- Configurable Argon2 password hashing cost parameters
- Secure,
HttpOnlycookies by default when cookie-based token issuance is enabled - Default account provisioning on startup, with configuration-driven role/verification sync
Data Models
This library provides variants of each of the following data models that can be used against a MongoDB or SQL database. Classes are post-fixed
with either Mongo or SQL at the end of the name (e.g. Alias becomes AliasMongo for MongoDB, AliasSQL for SQL).
User- Describes a single user accountAlias- Describes an alternate identifying name (aka: alias) for a user account (e.g. email, phone, third-party OAuth ID)Secret- Stores secrets used to authenticate user accounts (e.g.fido2,passkey,password,totp,recovery-codessecrets)Profile- Stores additional, personally identifying, information about a user (e.g. birthdate, legal name, verified contacts, preferences)
Route Handlers
This library provides variants of each of the following routes that can be used against a MongoDB or SQL database. Classes are post-fixed
with either Mongo or SQL at the end of the name (e.g. BaseAliasRoute becomes BaseAliasRouteMongo for MongoDB, BaseAliasRouteSQL for SQL).
Data Models
BaseAliasRoute- Provides full CRUD operations for theAliasdata modelBaseProfileRoute- Provides full CRUD operations for theProfiledata modelBaseSecretRoute- Provides full CRUD operations for theSecretdata model. Additionally includes endpoints for registration offido2,passkey,totpandrecovery-codessecrets.BaseUserRoute- Provides full CRUD operations for theUserdata model
Authentication Strategies
BaseAuthBasicRoute- Implements theBasicStrategyauthentication strategyBaseAuthFIDO2Route- Implements theFIDO2Strategyauthentication strategyBaseAuthMFARoute- Implements theMFAStrategyauthentication strategyBaseAuthOIDCRoute- Implements theOIDCStrategyauthentication strategyBaseAuthOTPRoute- Implements theOTPStrategyauthentication strategyBaseAuthPasskeyRoute- Implements thePasskeyStrategyauthentication strategyBaseAuthTOTPRoute- Implements theTOTPStrategyauthentication strategy
Session & Account Management
BaseAccountRoute- Aggregates a user's account data (profile, aliases, secrets) and provides account deletion and session revocationBaseAuthDiscoverRoute- Lets an anonymous caller discover which sign-in methods are configured for a claimed identifierBaseAuthElevationRoute- Issues a step-up (elevated) token after re-verifying identity, required for@RequiresElevation-gated actionsBaseAuthLogoutRoute- Clears the authentication cookie, if cookie-based token issuance is enabledBaseAuthRefreshRoute- Issues a new access token from a valid refresh tokenBaseRegistrationRoute- Self-service account registration via OTP-verified email or phone
Installation
NPM
npm i @rapidrest/authYarn
yarn add @rapidrest/authRequirements
This package targets Node.js >=24.0.0 and is published as an ESM-only package.
It declares @rapidrest/core and @rapidrest/service-core as required peer dependencies. The remaining peer
dependencies are optional and only need to be installed if you use the corresponding feature:
| Peer dependency | Required for |
| --- | --- |
| @rapidrest/core | Always |
| @rapidrest/service-core | Always |
| argon2 | Password (Basic, MFA) secrets — password hashing |
| otplib | TOTP, OTP, and MFA secrets/strategies |
| @simplewebauthn/server | Passkey and FIDO2 strategies |
| jwks-rsa | Verifying OIDC providers that publish a JWKS endpoint |
Strategies dynamically import() their optional dependency the first time they're used and throw a descriptive
error (naming the missing package) if it isn't installed, rather than failing at package install time.
License
MPL v2.0 — see LICENSE.
