Skip to content

Features

Multi-factor authentication

Included free on every install, with authenticator apps, backup codes and signing in with a passkey already enrolled. Enrolling a passkey and marking one as the backup key need a license with the mfa-pro feature. See pricing.

Multi-factor authentication adds a second step to admin sign-in. After the password, the person enters a code from an authenticator app or uses a passkey, so a stolen password alone does not open the account. Each person turns it on for their own account.

Each person turns it on for their own account:

  1. Open the account menu in the header and choose Two-factor authentication.
  2. Choose Turn on two-factor authentication.
  3. Scan the QR code with an authenticator app, or copy the Manual entry secret.
  4. Enter The 6-digit code from the app and choose Verify and turn on.
  5. Save the eight backup codes, or choose Copy all codes. They are shown once.

To turn it off, enter a current code or a backup code on the same page and choose Turn off.

To move to another authenticator app, enter a current code or a backup code on the same page and choose Replace the authenticator app, then scan the new QR code and verify a code from it. The old key keeps working until you do. An account that holds only a passkey confirms with Confirm with a passkey, or with a code, before it sets up an app.

The Two-factor authentication page during enrollment, with the QR code, the manual entry secret and the field for the six-digit code.

MethodUsed for
TOTPA six-digit code that changes every 30 seconds. Each code is accepted once, at sign-in as well as when TOTP is turned on or off or the backup codes are replaced. A code already used is refused, so wait for the app to show the next one.
Backup codesEight single-use codes shown when TOTP is turned on. Each one works once in place of a code.
Passkeys and security keysA second step, a sign-in without a password, or, for a key marked as the backup, a recovery sign-in. Enrolling one needs mfa-pro.

When an account holds a second factor, a password sign-in does not return a session, at POST /api/admin/auth/login or at the Content API's POST /api/v1/auth/token. It returns a challenge:

JSON
{
"mfa_required": true,
"challenge_token": "eyJhbGciOi...",
"mfa_methods": ["totp"]
}

mfa_methods lists totp for every account, and adds webauthn for an account that holds a passkey. A code finishes the challenge at POST /api/admin/auth/mfa-verify, and a passkey finishes it as Use passkeys shows. Each challenge gives one session, whichever factor finishes it, and expires five minutes after it is issued. The session acts in the tenant the password step signed in to, with the roles the account holds there when the challenge is finished. TOTP secrets are encrypted at rest with the instance's ENCRYPTION_KEY.

  1. TOTP and backup codes need nothing more. For passkeys, run with a license that carries mfa-pro. See licensing and tiers.
  2. For passkeys, set WEBAUTHN_RPID to the domain the console is served from, and WEBAUTHN_RP_ORIGINS to its origin. Set them before anyone registers a passkey.
  3. Restart the instance.

Each person then turns on an authenticator app in the console, as In the console shows. Passkeys are registered over the API, as Use passkeys shows.

This enrolls an authenticator app, signs in with it and turns it off. Use an account of your own.

Console v0.28.0

  1. Open the account menu in the header and choose Two-factor authentication, then Turn on two-factor authentication.
  2. Scan the QR code with an authenticator app, enter The 6-digit code from the app and choose Verify and turn on.
  3. Save the eight backup codes, or choose Copy all codes, then choose Done.

Engine API v0.62.0

Keep the account's token in TOKEN. The quickstart shows how to get one.

  1. Check the account's state:

    Shell
    curl http://localhost:3001/api/admin/mfa/status \
    -H "Authorization: Bearer $TOKEN"
    JSON
    { "enabled": false, "has_passkeys": false, "passkeys": [] }
  2. Start enrollment:

    Shell
    curl -X POST http://localhost:3001/api/admin/mfa/totp/setup \
    -H "Authorization: Bearer $TOKEN"
    JSON
    {
    "provisioning_uri": "otpauth://totp/LyEve:ada@example.com?algorithm=SHA1&digits=6&issuer=LyEve&period=30&secret=NY3NKSCE3CGYD7OHLXACNIGQZXREXM6Y",
    "secret": "NY3NKSCE3CGYD7OHLXACNIGQZXREXM6Y"
    }

    Add secret to an authenticator app, or show provisioning_uri as a QR code.

  3. Confirm with the code the app shows:

    Shell
    curl -X POST http://localhost:3001/api/admin/mfa/totp/verify \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"code": "123456"}'
    JSON
    { "enabled": true, "backup_codes": ["cee0a58bbf71c80d", "4be04c5798897db9", "..."] }

    Save the eight backup codes now. A wrong code answers 422 with invalid TOTP code.

Then sign in again. Wait for the app to show a new code first, because the code that turned TOTP on is spent.

Console v0.28.0

Sign out, then sign in with your email and password. The page asks for Two-factor verification. Enter a code from the app, or a backup code, in Authenticator code and choose Verify.

Engine API v0.62.0

  1. Sign in with POST /api/admin/auth/login. The answer is now the challenge shown above. Copy challenge_token into CHALLENGE.

  2. Finish the sign-in with a code from the app, or with a backup code:

    Shell
    curl -X POST http://localhost:3001/api/admin/auth/mfa-verify \
    -H "Content-Type: application/json" \
    -d '{"challenge_token": "'"$CHALLENGE"'", "code": "123456"}'

    The answer is a normal sign-in, with token and refresh_token. Copy token into TOKEN. Sending the same challenge again answers 401 with The MFA challenge has expired. Please log in again.

Turn it off with a current code or a backup code:

Console v0.28.0

On Two-factor authentication, enter the code in the Code field under Turn off and choose Turn off.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/mfa/totp/disable \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"code": "7cfaca44e9aae775"}'

The answer is 204.

The console has no screen for this on the current release, so it is an API call. POST /api/admin/mfa/backup-codes/regenerate with a current code in {"code": "123456"} replaces all eight with new ones and returns them as backup_codes. A code from the same 30-second window as the last code that turning TOTP on or off or replacing backup codes accepted is refused, so wait for the app to show the next code.

The first factor an account enrolls needs only the signed-in session. Once the account holds one (an authenticator app, a backup code or a passkey), setting up an authenticator app, registering a passkey and removing a passkey each need proof of a factor it already holds, in the request body:

  • {"code": "123456"}: a current code from the authenticator app, or an unused backup code in the same field. A backup code used this way is spent.
  • {"proof_session_id": "<session_id>", "assertion": {...}}: a passkey assertion. Get its challenge from POST /api/admin/mfa/proof/begin, which answers a session_id and the options for navigator.credentials.get(). The challenge proves a factor once and signs nobody in. The route answers 404 when the account has no passkey.

To replace an authenticator app:

Console v0.28.0

On Two-factor authentication, enter a current code or a backup code in the Code field under Replace the authenticator app and choose Replace the authenticator app. Scan the new QR code and verify a code from it. The page then shows eight new backup codes.

Engine API v0.62.0

Send the proof to POST /api/admin/mfa/totp/setup:

Shell
curl -X POST http://localhost:3001/api/admin/mfa/totp/setup \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"code": "123456"}'

The new key replaces the old one once POST /api/admin/mfa/totp/verify accepts a code from it.

A wrong proof counts toward the same lockout as a wrong code.

Removing a passkey with DELETE /api/admin/mfa/webauthn/credentials/{id} takes the same body. When that passkey is the last factor the account holds, with no authenticator app and no backup codes, removing it turns two-factor authentication off for the account.

A setup or a passkey registration started while the account held no factor does not finish once the account holds one: start it again with a proof. TOTP verify then answers 409 with mfa.totp.setup_unproven, and passkey registration answers 409 with mfa.webauthn.factor_added at the complete call.

Console v0.25.0 has no screen to register a passkey or to sign in with one, so this is done over the API, from a page of your own that calls the browser's navigator.credentials functions.

Registering a passkey and marking one as the backup key need mfa-pro. Every sign-in with a passkey stays free, so a passkey enrolled while the license covered it keeps working after a lapse, through the second step of a password sign-in, passwordless, cross-device and recovery sign-in alike. Listing, renaming and removing a passkey, and clearing its backup mark, are free too. Without mfa-pro the register routes answer 402 with {"error": "payment_required", "plugin": "mfa", "feature": "feature:mfa-pro", "upgrade_url": ""}.

Every WebAuthn route comes in a begin and complete pair:

  1. Call the begin route. It returns a session_id and the options to pass to the browser's navigator.credentials.create() or navigator.credentials.get().
  2. Send the browser's credential as the JSON body of the complete route, with ?session_id=<session_id> in the query.

Registration takes an optional &name= in the query of the complete call, and answers 201 with {"registered": true}.

To finish a password sign-in's challenge with a passkey, send {"challenge_token": "<challenge_token>"} to POST /api/admin/mfa/webauthn/auth/begin. The complete call, POST /api/admin/mfa/webauthn/auth/complete, takes both ?challenge_token=<challenge_token>&session_id=<session_id> in the query and answers {"token": "eyJhbGciOi..."}. Neither call needs a session. A challenge already finished, by a code or a passkey, answers 401 with invalid challenge token. Passwordless sign-in answers with a session:

JSON
{
"token": "eyJhbGciOi...",
"user_id": "5f0c...",
"email": "ada@example.com",
"expires_in": 900
}

The token lives for JWT_EXPIRY_SECS.

GET /api/admin/mfa/webauthn/credentials lists the person's passkeys as {"data": [...], "limit", "offset", "total_count"}, each with its id, name, is_backup, created_at and last_used_at, and GET /api/admin/mfa/status then reads "has_passkeys": true.

Mark a passkey as the backup key with PUT /api/admin/mfa/webauthn/credentials/{id}/backup and the body {"is_backup": true}. Recovery sign-in accepts only a backup key, and its begin call answers 400 no backup security key registered when the person has none.

A cross-device sign-in starts at POST /api/admin/auth/webauthn/cross-device/start, which returns a session_id, a qrcode_url and expires_at. It expires two minutes after it starts.

The console has no screen for this on the current release, so it is an API call. A super admin who acts across every tenant can turn off another person's MFA, for example when they lost their phone and their backup codes:

Shell
curl -X POST http://localhost:3001/api/admin/mfa/admin-reset \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"user_id": "5f0c7b1e-1d2a-4c3b-9e8f-0a1b2c3d4e5f", "reason": "Lost device, identity checked by phone"}'
JSON
{ "disabled": true, "target_user": "5f0c7b1e-1d2a-4c3b-9e8f-0a1b2c3d4e5f" }

reason is required and recorded with the reset. The person then enrolls again.

VariableWhat it doesDefault
WEBAUTHN_RPIDThe domain passkeys are bound to, such as admin.example.com.DOMAIN, then localhost
WEBAUTHN_RP_DISPLAY_NAMEThe name an authenticator shows for your instance.LyEve
WEBAUTHN_RP_ORIGINSComma-separated origins allowed to use passkeys. List a console development server's origin here.https://<rpid>
MFA_TOTP_ISSUERThe name shown against the entry in an authenticator app.the display name
PUBLIC_URLBase URL for the cross-device QR code when the request has no Origin header.https://localhost

Changing WEBAUTHN_RPID makes every passkey already registered unusable. The relying party settings take effect at restart. The issuer name and the token lifetime take effect without one. If you set LYEVE_PLUGINS, include mfa in it.

The routes under /api/admin/mfa act on the signed-in person and need a session, apart from the two under /api/admin/mfa/webauthn/auth. An admin token is refused on all of them. Those two and the routes under /api/admin/auth/webauthn run before a session exists, so they are public, each with its own rate limit.

Enrollment, passkeys and sign-in routes
MethodPathWhoPurpose
GET/api/admin/mfa/statussigned inWhether MFA is on, and the person's passkeys
POST/api/admin/mfa/totp/setupsigned inStart TOTP enrollment
POST/api/admin/mfa/totp/verifysigned inConfirm enrollment with a code and get backup codes
POST/api/admin/mfa/totp/disablesigned inTurn TOTP off with a current code or a backup code. 204
POST/api/admin/mfa/backup-codes/regeneratesigned inReplace the backup codes
POST/api/admin/mfa/webauthn/register/beginsigned inStart registering a passkey
POST/api/admin/mfa/webauthn/register/completesigned inFinish registering a passkey. 201
POST/api/admin/mfa/proof/beginsigned inStart a passkey check that proves a factor before one is added or removed
POST/api/admin/mfa/webauthn/auth/beginpublicStart finishing a password sign-in's challenge with a passkey
POST/api/admin/mfa/webauthn/auth/completepublicFinish a password sign-in's challenge with a passkey and get a token
GET/api/admin/mfa/webauthn/credentialssigned inList the person's passkeys
PUT/api/admin/mfa/webauthn/credentials/{id}/namesigned inRename a passkey
PUT/api/admin/mfa/webauthn/credentials/{id}/backupsigned inMark or unmark a passkey as the backup key
DELETE/api/admin/mfa/webauthn/credentials/{id}signed inRemove a passkey
POST/api/admin/mfa/admin-resetsuper_adminTurn off another person's MFA
POST/api/admin/auth/mfa-verifypublicExchange a challenge and a code for a session
POST/api/admin/auth/webauthn/login/beginpublicStart passwordless sign-in
POST/api/admin/auth/webauthn/login/completepublicFinish passwordless sign-in and get a token
GET/api/admin/auth/webauthn/conditionalpublicStart a sign-in offered through browser autofill
POST/api/admin/auth/webauthn/recovery/beginpublicStart a sign-in with the backup security key
POST/api/admin/auth/webauthn/recovery/completepublicFinish a recovery sign-in
POST/api/admin/auth/webauthn/cross-device/startpublicStart a cross-device sign-in and get a QR code URL
GET/api/admin/auth/webauthn/cross-device/{sessionID}/statuspublicPoll a cross-device sign-in
GET/api/admin/auth/webauthn/cross-device/{sessionID}/qrpublicFetch the QR code payload
POST/api/admin/auth/webauthn/cross-device/completepublicApprove a cross-device sign-in from the phone

At the password step (POST /api/admin/auth/login and POST /api/v1/auth/token):

StatusMessageCause
503Multi-factor authentication is temporarily unavailable. Please try again later., code AUTH_MFA_STORE_ERRORThe account's second factors could not be read. The password is not refused and no session is issued, so try again.

At sign-in (POST /api/admin/auth/mfa-verify):

StatusMessageCause
422The provided verification code is invalid.The code is wrong and is not an unused backup code. A wrong six-digit code counts toward the lockout even while backup codes cannot be read.
429Too many MFA verification attempts. Please log in again to receive a new challenge.5 wrong codes for the account within 15 minutes, or 5 tries on one challenge.

On the routes under /api/admin/mfa:

StatusMessageCause
422invalid TOTP code or invalid codeThe code is wrong or was already used.
429too many verification attempts, try again laterMore than 5 code checks in 5 minutes.
429account temporarily locked due to too many failed attempts10 failures in a row lock code checks for 30 minutes.

Adding or removing a factor on an account that already holds one answers these codes in the code field:

StatusCodeCause
400mfa.totp.current_code_requiredAuthenticator setup sent no proof.
422mfa.totp.current_code_invalidAuthenticator setup sent a proof that matches no factor the account holds.
400mfa.webauthn.proof_requiredPasskey registration or removal sent no proof.
422mfa.webauthn.proof_invalidPasskey registration or removal sent a proof that matches no factor the account holds.
409mfa.totp.setup_unprovenThe authenticator setup started without proof, before the account held a factor. Start it again.
409mfa.webauthn.factor_addedThe passkey registration started without proof, and the account gained a factor before it finished. Start it again.
Every other error
StatusMessageCause
429too many setup attempts, try again laterMore than 3 setup calls in an hour.
400no pending TOTP enrollmentVerify was called before setup on an account that never started enrollment. After a turn-off, the same call answers 503 with mfa verification error.
400MFA not enabledDisable or regenerate was called on an account without MFA.
409The authenticator setup changed while this code was checked. Start setup again.Another setup, verify or turn-off changed the pending key while TOTP verify checked the code.
401The MFA challenge has expired. Please log in again.The challenge was used already or ran out.
401invalid challenge tokenA passkey tried to finish a challenge that was used already, ran out or belongs to another tenant's domain.
403admin-reset requires platform-level super_admin (no tenant scope)A super admin acting in one tenant called the reset.
503WebAuthn not configuredA passkey route was called while passkeys cannot run.
402payment_requiredRegistering a passkey, or marking one as the backup key, without mfa-pro.
404no passkey is registered on this accountA passkey proof was started on an account with no passkey.
503failed to delete credentialRemoving a passkey failed on the server. Nothing was removed, so try again.
  • The browser refuses to create a passkey. WEBAUTHN_RPID must be the console's domain or a parent of it, and the page's origin must be in WEBAUTHN_RP_ORIGINS.
  • The QR code points at https://localhost. Set PUBLIC_URL to the instance's public address.
  • Someone is locked out of every factor. A super admin resets their MFA, and they enroll again.