RedisTwoFactorStore
The TwoFactorStore on Redis.
Implements
Section titled “Implements”TwoFactorStore
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RedisTwoFactorStore(
redis,options?):RedisTwoFactorStore
Parameters
Section titled “Parameters”Redis
options?
Section titled “options?”RedisStoreOptions = {}
Returns
Section titled “Returns”RedisTwoFactorStore
Methods
Section titled “Methods”addTrustedDevice()
Section titled “addTrustedDevice()”addTrustedDevice(
device,maxPerUser):Promise<void>
Stores a trusted device, then deletes the user’s oldest devices beyond
maxPerUser. May drop it after expiresAt.
Parameters
Section titled “Parameters”device
Section titled “device”StoredTrustedDevice
maxPerUser
Section titled “maxPerUser”number
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”TwoFactorStore.addTrustedDevice
advanceStep()
Section titled “advanceStep()”advanceStep(
userId,step):Promise<boolean>
Compare-and-set: sets lastStep to step only if the factor is confirmed
and its lastStep is below step, in one atomic write. Of many
concurrent callers with the same step, at most one gets true.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
number
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”TwoFactorStore.advanceStep
confirmFactor()
Section titled “confirmFactor()”confirmFactor(
userId,secret,step):Promise<boolean>
Compare-and-set: confirms the factor and sets lastStep to step only if
it is still pending and its secret still equals secret, in one atomic
write. Returns whether it did.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
secret
Section titled “secret”string
number
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”TwoFactorStore.confirmFactor
consumeRecoveryCode()
Section titled “consumeRecoveryCode()”consumeRecoveryCode(
userId,hash):Promise<boolean>
Removes one recovery code atomically: of many concurrent callers exactly one gets true.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
string
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”TwoFactorStore.consumeRecoveryCode
countRecoveryCodes()
Section titled “countRecoveryCodes()”countRecoveryCodes(
userId):Promise<number>
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<number>
Implementation of
Section titled “Implementation of”TwoFactorStore.countRecoveryCodes
deleteFactor()
Section titled “deleteFactor()”deleteFactor(
userId):Promise<void>
Deletes the factor, pending or confirmed.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”TwoFactorStore.deleteFactor
deleteTrustedDevices()
Section titled “deleteTrustedDevices()”deleteTrustedDevices(
userId):Promise<void>
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”TwoFactorStore.deleteTrustedDevices
findFactor()
Section titled “findFactor()”findFactor(
userId):Promise<StoredTotpFactor|null>
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<StoredTotpFactor | null>
Implementation of
Section titled “Implementation of”TwoFactorStore.findFactor
findStepUp()
Section titled “findStepUp()”findStepUp(
sessionId):Promise<StoredStepUp|null>
The session’s step-up proof (expired or not: the caller checks).
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
Returns
Section titled “Returns”Promise<StoredStepUp | null>
Implementation of
Section titled “Implementation of”TwoFactorStore.findStepUp
findTrustedDevice()
Section titled “findTrustedDevice()”findTrustedDevice(
userId,hash):Promise<StoredTrustedDevice|null>
The device with this hash if it belongs to userId (expired or not: the caller checks).
Parameters
Section titled “Parameters”userId
Section titled “userId”string
string
Returns
Section titled “Returns”Promise<StoredTrustedDevice | null>
Implementation of
Section titled “Implementation of”TwoFactorStore.findTrustedDevice
putPendingFactor()
Section titled “putPendingFactor()”putPendingFactor(
factor):Promise<boolean>
Stores a pending (unconfirmed) factor with lastStep -1, replacing a
pending one. Never replaces a confirmed factor: returns false (and writes
nothing) when the user has one.
Parameters
Section titled “Parameters”factor
Section titled “factor”createdAt
Section titled “createdAt”number
secret
Section titled “secret”string
userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”TwoFactorStore.putPendingFactor
putStepUp()
Section titled “putStepUp()”putStepUp(
stepUp):Promise<void>
Stores (or replaces) the step-up proof of a session. May drop it after expiresAt.
Parameters
Section titled “Parameters”stepUp
Section titled “stepUp”StoredStepUp
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”TwoFactorStore.putStepUp
replaceRecoveryCodes()
Section titled “replaceRecoveryCodes()”replaceRecoveryCodes(
userId,hashes):Promise<void>
Replaces the user’s recovery codes with hashes in one atomic write (an empty list deletes them).
Parameters
Section titled “Parameters”userId
Section titled “userId”string
hashes
Section titled “hashes”readonly string[]
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”TwoFactorStore.replaceRecoveryCodes