Abstract Class: BaseAuthElevationRouteMongo
Defined in: src/routes/mongo/BaseAuthElevationRouteMongo.ts:8
Issues an elevated access token (see TokenUtils.createAccessToken's elevated argument, and the
@RequiresElevation decorator in @rapidrest/service-core) once the caller — who must already hold a
valid, non-elevated access token — has freshly re-proven their identity. Only an elevated token carries
the caller's trusted roles — a normal, non-elevated token never does — so this route is what turns a
plain "I'm logged in" session into "I've recently confirmed I'm still me" for the specific request(s)
that need it.
This is deliberately a lightweight, single-factor "prove you're still you" check, NOT a full
re-authentication: the caller already proved their identity once to obtain their current access token
(see @Auth(["jwt"]) below), so this route only asks for one additional method:
- A caller who has enrolled at least one secondary method (OTP/TOTP/FIDO2) must complete exactly one of
them —
GETlists the caller's own available methods, andPOSTboth begins and completes a challenge for a selected one (mirroringBaseAuthMFARoute's phase 2/3, but scoped to the caller's own uid throughout since identity is already established via the JWT, never taken from the request body). - A caller with no secondary method enrolled (most commonly a freshly bootstrapped default admin
account, which typically only has a password) elevates by resubmitting their password instead. Without
this, such an account could never satisfy
@RequiresElevation-gated actions at all, since it has no second factor to prove — a permanent lockout, not a security improvement. Password resubmission is only accepted when zero secondary methods are enrolled — once a real second factor exists, it must be used, since re-supplying the same password used to obtain the current token proves nothing new.
Extends
Constructors
Constructor
new BaseAuthElevationRouteMongo():
BaseAuthElevationRouteMongo
Returns
BaseAuthElevationRouteMongo
Inherited from
BaseAuthElevationRoute.constructor
Properties
aliasClass
protectedaliasClass:any=AliasMongo
Defined in: src/routes/mongo/BaseAuthElevationRouteMongo.ts:9
Overrides
BaseAuthElevationRoute.aliasClass
aliasRepo?
protectedoptionalaliasRepo?:RepoUtils<AliasMongo>
Defined in: src/routes/BaseAuthElevationRoute.ts:81
Inherited from
BaseAuthElevationRoute.aliasRepo
defaultScopes
protecteddefaultScopes:string[] =[]
Defined in: src/routes/BaseAuthElevationRoute.ts:84
Inherited from
BaseAuthElevationRoute.defaultScopes
fido2Config
protectedfido2Config:PasskeyConfig
Defined in: src/routes/BaseAuthElevationRoute.ts:92
The relying party configuration to use for the FIDO2 elevation method. See
BaseAuthFIDO2Route/BaseSecretRoute.fido2Config for the primary-auth/registration counterparts of
this configuration.
Inherited from
BaseAuthElevationRoute.fido2Config
logger
protectedlogger:any
Defined in: src/routes/BaseAuthElevationRoute.ts:99
Inherited from
messagingUtils?
protectedoptionalmessagingUtils?:MessagingUtils
Defined in: src/routes/BaseAuthElevationRoute.ts:102
Inherited from
BaseAuthElevationRoute.messagingUtils
rateLimiter?
protectedoptionalrateLimiter?:RateLimiter
Defined in: src/routes/BaseAuthElevationRoute.ts:105
Inherited from
BaseAuthElevationRoute.rateLimiter
secretClass
protectedsecretClass:any=SecretMongo
Defined in: src/routes/mongo/BaseAuthElevationRouteMongo.ts:10
Overrides
BaseAuthElevationRoute.secretClass
secretRepo?
protectedoptionalsecretRepo?:RepoUtils<SecretMongo>
Defined in: src/routes/BaseAuthElevationRoute.ts:107
Inherited from
BaseAuthElevationRoute.secretRepo
template
protectedtemplate:string="login-otp"
Defined in: src/routes/BaseAuthElevationRoute.ts:110
The name of the messaging template to use for sending notifications.
Inherited from
BaseAuthElevationRoute.template
tokenUtils?
protectedoptionaltokenUtils?:TokenUtils
Defined in: src/routes/BaseAuthElevationRoute.ts:120
Inherited from
BaseAuthElevationRoute.tokenUtils
totpConfig
protectedtotpConfig:TOTPConfig
Defined in: src/routes/BaseAuthElevationRoute.ts:117
Only encryption_key is read here — the rest of TOTPConfig (digits/period/algorithm/etc.) is
captured onto each TOTPSecret at registration time by BaseSecretRoute, not re-read on elevation.
Inherited from
BaseAuthElevationRoute.totpConfig
trustedProxies
protectedtrustedProxies:string[] =[]
Defined in: src/routes/BaseAuthElevationRoute.ts:123
Inherited from
BaseAuthElevationRoute.trustedProxies
userClass
protecteduserClass:any=UserMongo
Defined in: src/routes/mongo/BaseAuthElevationRouteMongo.ts:11
Overrides
BaseAuthElevationRoute.userClass
userRepo?
protectedoptionaluserRepo?:RepoUtils<UserMongo>
Defined in: src/routes/BaseAuthElevationRoute.ts:125
Inherited from
BaseAuthElevationRoute.userRepo
userUtils?
protectedoptionaluserUtils?:UserUtils<UserMongo,AliasMongo>
Defined in: src/routes/BaseAuthElevationRoute.ts:127
Inherited from
BaseAuthElevationRoute.userUtils
Methods
beginChallenge()
protectedbeginChallenge(methodId,user,req):Promise<any>
Defined in: src/routes/BaseAuthElevationRoute.ts:275
Begins a challenge for one of the caller's own elevation methods. Scoped to user.uid throughout via
getMethod() — the same authorization boundary BaseAuthMFARoute relies on — so a methodId
belonging to another user can never be used here.
Parameters
methodId
string
user
JWTUser
req
HttpRequest
Returns
Promise<any>
Inherited from
BaseAuthElevationRoute.beginChallenge
convertAliasToMethod()
protectedconvertAliasToMethod(alias,obfuscate?):MFAMethod|undefined
Defined in: src/routes/BaseAuthElevationRoute.ts:416
Parameters
alias
obfuscate?
boolean
Returns
MFAMethod | undefined
Inherited from
BaseAuthElevationRoute.convertAliasToMethod
convertSecretToMethod()
protectedconvertSecretToMethod(secret):MFAMethod|undefined
Defined in: src/routes/BaseAuthElevationRoute.ts:456
Parameters
secret
Returns
MFAMethod | undefined
Inherited from
BaseAuthElevationRoute.convertSecretToMethod
elevate()
elevate(
obj,user,req,res):Promise<any>
Defined in: src/routes/BaseAuthElevationRoute.ts:205
Re-verifies the caller's identity using exactly one additional method beyond their existing access token, and on success returns a fresh elevated access token (and refresh token) for them to use with the specific request(s) that require it. Accepts, in the request body:
{ methodId }— begins a challenge for one of the caller's own methods (fromlistMethods()). For FIDO2 this returns a WebAuthn assertion challenge; for OTP this sends a code to the associated contact; for TOTP this returns an empty body (the caller's authenticator app already has the current code).{ token }(OTP/TOTP) or a WebAuthn assertion response (FIDO2) — completes the challenge begun above.{ password }— only accepted when the caller has zero secondary methods enrolled.
Parameters
obj
any
user
JWTUser
req
HttpRequest
res
HttpResponse
Returns
Promise<any>
Inherited from
BaseAuthElevationRoute.elevate
getCredentialById()
protectedgetCredentialById(credentialId):Promise<StoredPasskeyCredential|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:480
Retrieves a previously-registered FIDO2 credential by its ID, for verifying a FIDO2 elevation challenge response.
Parameters
credentialId
string
The unique id of the FIDO2 credential to retrieve.
Returns
Promise<StoredPasskeyCredential | undefined>
Inherited from
BaseAuthElevationRoute.getCredentialById
getMethod()
protectedgetMethod(id,userUid):Promise<MFAMethod|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:504
Retrieves the user's elevation method for a given id. Only returns a method that actually belongs to
uid — this is what stops one user's elevation challenge from being triggered/consumed using another
user's authentication method.
Parameters
id
string
The unique id of the elevation method to retrieve.
userUid
string
The unique id of the user the method must belong to.
Returns
Promise<MFAMethod | undefined>
Inherited from
BaseAuthElevationRoute.getMethod
getMethods()
protectedgetMethods(uid):Promise<MFAMethod[]>
Defined in: src/routes/BaseAuthElevationRoute.ts:537
Retrieves the list of elevation methods for the user with the given id. This list is sent to the user and so should be obfuscated where reasonable so as to limit discovery when a password has been compromised.
Parameters
uid
string
The unique identifier of the user.
Returns
Promise<MFAMethod[]>
Inherited from
BaseAuthElevationRoute.getMethods
getUser()
protectedgetUser(uid):Promise<JWTUser|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:587
Retrieves the user with the given unique id.
Parameters
uid
string
The unique id of the user to retrieve.
Returns
Promise<JWTUser | undefined>
The user if found, otherwise undefined.
Inherited from
BaseAuthElevationRoute.getUser
initialize()
protectedinitialize():Promise<void>
Defined in: src/routes/BaseAuthElevationRoute.ts:133
Called on server startup to initialize the route with any defaults.
Returns
Promise<void>
Inherited from
BaseAuthElevationRoute.initialize
listMethods()
listMethods(
user):Promise<MFAMethod[]>
Defined in: src/routes/BaseAuthElevationRoute.ts:179
Returns the authenticated caller's own available secondary methods for elevating — see elevate().
An empty list means the caller has none enrolled and must elevate via password instead.
Parameters
user
JWTUser
Returns
Promise<MFAMethod[]>
Inherited from
BaseAuthElevationRoute.listMethods
notifyContact()
protectednotifyContact(contact,totp):Promise<void>
Defined in: src/routes/BaseAuthElevationRoute.ts:594
Parameters
contact
totp
string
Returns
Promise<void>
Inherited from
BaseAuthElevationRoute.notifyContact
obfuscateAlias()
protectedobfuscateAlias(alias,type):string
Defined in: src/routes/BaseAuthElevationRoute.ts:617
Obfuscates the given alias and returns the obfuscated value.
Parameters
alias
string
type
Returns
string
Inherited from
BaseAuthElevationRoute.obfuscateAlias
updateCredentialCounter()
protectedupdateCredentialCounter(credentialId,newCounter):Promise<void>
Defined in: src/routes/BaseAuthElevationRoute.ts:641
Persists the updated signature counter for the given FIDO2 credential after a successful elevation challenge. Called on every successful FIDO2 elevation to guard against cloned authenticators.
Parameters
credentialId
string
The unique id of the credential to update.
newCounter
number
The new signature counter value to persist.
Returns
Promise<void>
Inherited from
BaseAuthElevationRoute.updateCredentialCounter
updateSecretTimeStep()
protectedupdateSecretTimeStep(uid,timeStep):Promise<void>
Defined in: src/routes/BaseAuthElevationRoute.ts:675
Persists the given time step as the last one successfully used for the identified TOTP secret, so a captured/replayed token can't be reused within its validity window.
Closes a TOCTOU race between two concurrent elevation requests both holding the same valid code:
each independently verifies the submitted token before either one reaches this method, so
verification alone can't tell them apart. Re-checking lastTimeStep against a fresh read here -
combined with RepoUtils.update()'s existing optimistic-locking version check, which still
protects the case where both readers see the same pre-update state - means at most one of the two
ever succeeds in claiming this time step; the loser throws instead of silently letting a second
session elevate on an already-used code.
Parameters
uid
string
The unique id of the stored secret that was verified.
timeStep
number
The RFC 6238 time step at which the token was verified.
Returns
Promise<void>
Inherited from
BaseAuthElevationRoute.updateSecretTimeStep
verify()
protectedverify(name,password):Promise<JWTUser|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:699
Parameters
name
string
password
string
Returns
Promise<JWTUser | undefined>
Inherited from
verifyFIDOChallenge()
protectedverifyFIDOChallenge(payload,req):Promise<JWTUser|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:359
Parameters
payload
any
req
HttpRequest
Returns
Promise<JWTUser | undefined>
Inherited from
BaseAuthElevationRoute.verifyFIDOChallenge
verifyOTPChallenge()
protectedverifyOTPChallenge(payload,req):Promise<JWTUser|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:315
Parameters
payload
any
req
HttpRequest
Returns
Promise<JWTUser | undefined>
Inherited from
BaseAuthElevationRoute.verifyOTPChallenge
verifyPasswordOnly()
protectedverifyPasswordOnly(user,password):Promise<JWTUser|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:399
Verifies the caller's password as their sole proof of elevation. Only valid when the caller has no secondary method enrolled — once a real second factor exists it must be used instead, since resubmitting the same password used to obtain the current access token proves nothing new.
Parameters
user
JWTUser
password
string
Returns
Promise<JWTUser | undefined>
Inherited from
BaseAuthElevationRoute.verifyPasswordOnly
verifyTOTPChallenge()
protectedverifyTOTPChallenge(payload,req):Promise<JWTUser|undefined>
Defined in: src/routes/BaseAuthElevationRoute.ts:332
Parameters
payload
any
req
HttpRequest
Returns
Promise<JWTUser | undefined>