Two-factor sign-in
Two-factor sign-in asks for a six digit code from an authenticator app every time someone signs in to the Admin UI with a username and password. A stolen password alone is then not enough to get in. Each person sets it up for their own account and gets ten recovery codes for the day they lose their phone. An admin can require it for every password sign-in, an organization admin can require it for their organization, and a proxy admin can reset it for a user who is locked out. It does not apply to single sign-on, which uses your identity provider's own checks.
When you would use this
An administrator's laptop is stolen with the browser still remembering the Admin UI password. With two-factor sign-in on, the thief is stopped at the code prompt. The administrator signs in from another device with a recovery code, replaces the recovery codes, and nothing else needs to change.
Before you start
The gateway needs its database, because enrollments and recovery codes are stored there. The settings below are optional. Everything on this page works from a signed-in Admin UI session, never with an API key, so the curl examples use the session's bearer token, which the Admin UI sends as Authorization: Bearer.
general_settings:
require_mfa_for_password_login: true
Step by step
-
Set it up for yourself. Open the account menu at the bottom of the left sidebar, click Change Password, and find the Two-factor sign-in card under the password form. Click Set up an authenticator app. Scan the QR code, or open Open in an authenticator app on this device, or type the setup key shown under "Or enter this setup key by hand". Over the API the same step is
POST /user/mfa/enrollwith an empty body.curl -X POST http://localhost:4000/user/mfa/enroll \-H "Authorization: Bearer $SESSION_TOKEN" \-H "Content-Type: application/json" \-d '{}'{"otpauth_uri": "otpauth://totp/Spanway:dev%40example.com?secret=JBSWY3DPEHPK3PXP&issuer=Spanway","secret": "JBSWY3DPEHPK3PXP"} -
Confirm with a code. Type the six digit code from the app under Code from the app and click Turn on. Nothing is enforced until this code is accepted. Over the API call
POST /user/mfa/enroll/confirm.curl -X POST http://localhost:4000/user/mfa/enroll/confirm \-H "Authorization: Bearer $SESSION_TOKEN" \-H "Content-Type: application/json" \-d '{"code": "123456"}'{"recovery_codes": ["7f3k-29ab", "c81d-04qz"]}The card shows the ten recovery codes once, with Copy and Download buttons, and Done hides them. Each code signs you in once if you lose your authenticator. Store them somewhere safe, because they cannot be shown again.
-
Sign in. The next time you sign in with your username and password the login page asks for the code from your app. If you lost the app, enter one of your recovery codes instead. When two-factor sign-in is required for an account that has not set it up, the login page shows "Two-factor sign-in is required for your account. Sign in here to continue." and walks through the setup before letting the person in.
-
Check your status and replace your codes. The card reads "On. N recovery codes left." Enter a current code under Code to replace recovery codes and click New codes to get ten new ones. The old codes stop working. Over the API read
GET /user/mfaand callPOST /user/mfa/recovery_codes.curl http://localhost:4000/user/mfa -H "Authorization: Bearer $SESSION_TOKEN"curl -X POST http://localhost:4000/user/mfa/recovery_codes \-H "Authorization: Bearer $SESSION_TOKEN" \-H "Content-Type: application/json" \-d '{"code": "123456"}'{"enrolled": true, "required": false, "recovery_codes_remaining": 10} -
Turn it off. Enter a current code under Code to turn it off and click Turn off, or call
POST /user/mfa/disable. When it is required for your account the control is replaced by "It is required for your account, so it cannot be turned off." and the gateway refuses the call.curl -X POST http://localhost:4000/user/mfa/disable \-H "Authorization: Bearer $SESSION_TOKEN" \-H "Content-Type: application/json" \-d '{"code": "123456"}' -
Require it. For every password sign-in, set
require_mfa_for_password_login: trueundergeneral_settingsand restart. For one organization, open Organizations, click the organization, open the Settings tab, switch on Require two-factor sign-in and click Save Changes, or sendrequire_mfaon/organization/new,PATCH /organization/updateorPATCH /v2/organization/{organization_id}. Members of that organization, by home organization or by membership, are then asked to set it up at their next sign-in. Requiring it for an organization needs an Enterprise license, whilerequire_mfa_for_password_loginand two-factor sign-in itself work on every tier.curl -X PATCH http://localhost:4000/organization/update \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"organization_id": "org-research", "require_mfa": true}' -
Reset it for someone who is locked out. A user who lost both their phone and their recovery codes asks a proxy admin. Open Internal Users, open the user's detail view, click Reset two-factor and confirm Reset two-factor sign-in?, or call
POST /user/mfa/resetwith a proxy admin key. It removes the setup and signs the user out of every Admin UI session. If two-factor sign-in is required for them, they set it up again at their next sign-in.curl -X POST http://localhost:4000/user/mfa/reset \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"user_id": "user-123"}'{"message": "Two-factor sign-in reset, 2 sessions revoked"}
What you should see
After setup the login page asks for a code after the password, a wrong code shows "Invalid code" and repeated wrong codes are throttled by the gateway's sign-in attempt limits. Each sign-in with a recovery code uses that code up, and the response tells the Admin UI how many codes remain. Every enrollment, disable, code replacement and admin reset writes an audit log row for the user. When two-factor sign-in is required and the database is unreachable, password sign-in fails with 503 instead of letting the user in without a code.
| Method | Path | Summary |
|---|---|---|
| GET | /user/mfa | Two-factor status of the signed-in user |
| POST | /user/mfa/enroll | Start setting up an authenticator app |
| POST | /user/mfa/enroll/confirm | Finish two-factor setup with a code |
| POST | /user/mfa/disable | Turn off two-factor sign-in |
| POST | /user/mfa/recovery_codes | Replace your recovery codes |
| POST | /user/mfa/reset | Reset a user's two-factor sign-in |
Errors
| Error | Cause | Fix |
|---|---|---|
403 Two-factor settings can only be changed from a signed-in Admin UI session | The call used a virtual key or the master key. | Sign in to the Admin UI and use its session, or use the card on the Change Password page. |
409 Two-factor sign-in is already set up. Disable it first to start over. | /user/mfa/enroll was called while enrolled. | Turn it off with a current code, then enroll again. |
409 Two-factor sign-in is not set up for this account | Disable or recovery codes were requested before setup. | Set it up first. |
401 Invalid code | The code is wrong or expired. Codes change every 30 seconds. | Check the device clock and try the current code. |
403 Two-factor sign-in is required for this account and cannot be turned off | The gateway or one of your organizations requires it. | Leave it on, or ask the admin to drop the requirement. |
403 Only proxy admins can reset two-factor sign-in | A non admin called /user/mfa/reset. | Use a proxy admin key. |
401 This sign-in has expired or was already used. Sign in again. | The login page waited too long between the password and the code. | Sign in again from the start. |
403 This feature is only available for Spanway Enterprise users: require_mfa. | require_mfa: true was sent for an organization without an Enterprise license. | Add an Enterprise license, or use require_mfa_for_password_login under general_settings. |
503 on password sign-in | Two-factor sign-in is required and the database is unreachable. | Restore the database connection. The gateway does not skip the code check. |
Related
- Security settings for
require_mfa_for_password_login, password rules and sign-in throttling. - Account page for the Change Password page and the two-factor card.
- Organizations and the Organizations page for the per organization switch.
- Internal Users page for the admin reset.
- Audit logs for the rows each change writes.