---
title: "Set up multi-factor authentication"
sidebarTitle: "Set up MFA"
description: "Enrol an authenticator app or a passkey on your own account, keep your recovery codes usable, and require a second factor for every member of an organization."
keywords: ["MFA", "two-factor", "2FA", "TOTP", "authenticator", "passkey", "WebAuthn", "recovery codes", "mfa policy"]
---

TRUSTIVAN has two kinds of second factor: a time-based one-time password
(TOTP) from an authenticator app, six digits and a new code every 30 seconds;
and a **passkey** (WebAuthn), the fingerprint, face or PIN of a device or a
password manager. This page covers turning them on for yourself, and, if you
own an organization, requiring one for everyone.

A second factor applies to **people**. An API key or a workload credential has
none, and the endpoints below refuse one with `403`.

## Turn it on for your account

<Steps>
  <Step title="Start enrolment">
    Open **Settings → Security** and start setting up two-factor
    authentication. TRUSTIVAN issues a secret and shows it as a QR code and as
    text.

    Over the API this is `POST /api/v1/auth/mfa/enroll`. The response carries
    `secret` and `provisioning_uri` (an `otpauth://` URI), and it is the only
    time the secret is returned. A `409` means you are already enrolled.
  </Step>
  <Step title="Add it to your authenticator">
    Scan the code, or paste the secret, into an authenticator app that
    supports TOTP.
  </Step>
  <Step title="Confirm with a code">
    Enter the six-digit code the app shows. This is
    `POST /api/v1/auth/mfa/confirm` with `{"code": "123456"}`.

    Until you confirm, the factor challenges nobody: an enrolment you started
    and abandoned does not protect your sign-in, and Settings says so.
  </Step>
  <Step title="Store your recovery codes">
    Confirming returns ten recovery codes. They are stored hashed and cannot
    be shown again, so put them in your password manager now.
  </Step>
</Steps>

Confirming signs you out everywhere else. Every other session on your account
is revoked, and the browser you enrolled from is given a fresh one.

## Signing in afterwards

A correct password no longer returns a session. `POST /api/v1/auth/login`
answers `200` with `mfa_required: true` and a `challenge_token`, and sets no
cookies. Branch on `mfa_required`, not on the status code. The session is
issued only when that token is exchanged with a code:

```bash
curl -s -X POST https://app.trustivan.com/api/v1/auth/mfa/verify \
  -H 'Content-Type: application/json' \
  -c cookies.txt \
  -d '{"challenge_token": "…", "code": "123456"}'
```

`code` is a current TOTP code or a recovery code. Both are single-use: a TOTP
code that has already been spent on your account is refused even inside its
30-second window.

A challenge lasts five minutes and allows five attempts. Every failure (wrong
code, replayed code, expired or unknown challenge, attempts used up) is the
same `401`. If you run out, sign in with your password again to get a new
challenge.

## Recovery codes

Each recovery code works once, in place of a TOTP code, anywhere a code is
asked for at sign-in. They are the only self-service way back into an account
whose authenticator is lost.

Settings warns you when you are nearly out. `GET /api/v1/auth/mfa` reports the
same thing:

```json
{ "enabled": true, "pending_enrolment": false, "recovery_codes_left": 3 }
```

To replace the set, use **Settings → Security** or
`POST /api/v1/auth/mfa/recovery-codes` with a current TOTP code or an unused
recovery code. Every previous code stops working the moment the new set is
returned.

## Passkeys

Open **Settings → Security → Passkeys** and choose **Add a passkey**. Your
browser asks you to confirm with the device (Touch ID, Windows Hello, a phone
or a security key) or to save it in your password manager. An account can hold
up to 20.

A passkey does two things:

- **Passwordless sign-in.** **Sign in with a passkey** on the sign-in page
  signs you in with no password. The device verifies you (PIN or biometric), so
  this is two factors in one gesture. The same SSO enforcement applies as to a
  password.
- **Second factor.** Once you hold a passkey, a password alone no longer signs
  you in: `POST /api/v1/auth/login` answers `mfa_required` with
  `methods: ["passkey", "recovery_code"]` (plus `totp` if you also have an
  authenticator app), and **Use a passkey** finishes the sign-in.

A passkey satisfies an organization's MFA policy exactly as TOTP does. Your
first passkey issues recovery codes if you have none; they work in the code
field of the sign-in challenge.

Removing a passkey needs a fresh proof as well as your session: confirm with a
passkey, or enter an authenticator or recovery code. If your organization
requires a second factor, the last one you hold cannot be removed until you
add another.

Over the API: `POST /api/v1/auth/passkeys/options`, then `POST
/api/v1/auth/passkeys` with the browser's answer; `/auth/passkey/login/options`
and `/auth/passkey/login` for passwordless sign-in. The browser ceremony needs
the dashboard's origin; a deployment whose dashboard is not at `DASHBOARD_URL`
sets `WEBAUTHN_RP_ID` and `WEBAUTHN_ORIGINS`
([environment](/configuration/environment)). A passkey is bound to its relying
party ID for life: changing it means every passkey is registered again.

## Turn it off

**Settings → Security**, or `DELETE /api/v1/auth/mfa` with `{"code": "…"}`.

A current code or a recovery code is required as well as your session.
Removing the factor is exactly what somebody holding a stolen session would
want to do, so the session alone does not authorize it.

If your organization requires a second factor, you are sent through enrolment
again at your next sign-in.

## Require it for everyone

An owner can require a second factor for every member, under
**Settings → Security → Require two-factor authentication** or:

```bash
curl -s -X PUT https://app.trustivan.com/api/v1/identity/mfa-policy \
  -H 'Content-Type: application/json' \
  -b cookies.txt \
  -H "X-CSRF-Token: $(grep trustivan_csrf cookies.txt | awk '{print $7}')" \
  -d '{"require_mfa": true}'
```

This needs `identity:manage`, which only the `owner` role holds and no API key
can be granted. Once it is on:

- A member with no confirmed factor is held at enrolment on their next
  password or social sign-in, **before** any session exists. The sign-in
  answers with `mfa_enrollment_required: true` and a challenge token, and the
  dashboard walks them through the same four steps as above.
- A member with no confirmed factor cannot renew a session they already have.
- **Single sign-on sessions are exempt.** Your identity provider owns that
  factor, so enforce it there.

Every change to the policy is recorded in the identity audit trail as
`mfa_policy.changed`.

<Tip>
  Enrol your own factor before you switch the policy on. You find out how
  enrolment behaves before your colleagues do, and an owner with a second
  factor is also the one account that can still sign in with a password when
  [single sign-on is required](/how-to/set-up-single-sign-on#6-require-single-sign-on)
  and your identity provider is unavailable.
</Tip>

## Where a code is asked for again

A second factor is not only checked at sign-in. With one enrolled, you are
asked for a current TOTP code when you:

- change your password (a recovery code is not accepted here);
- [approve an irreversible action by an AI agent](/how-to/govern-an-ai-agent#approve-an-irreversible-action).

## See also

- [Manage your account](/how-to/manage-your-account): password, email
  verification and signing out everywhere.
- [Credential handling](/security/credentials): how session credentials are
  issued and bounded.
