Skip to main content

Adaptive MFA and bot protection

Ask for a second factor only when a sign-in looks risky, and stop automated sign-up with a CAPTCHA.

RecipeDraftView source
This page is a draft. The code exists, and not all of it has been run for this page yet. The page says what was checked.
Packages
lumo
Works with
lumo CLI

What it shows​

  1. The risk engine scores every sign-in from 0 to 100, from the signals that are switched on and included in your plan.
  2. A score below the medium threshold, 50 by default, lets the sign-in through. A score at or above it asks for the second factor.
  3. A person who has no second factor follows one setting. The script sets it to email: LumoAuth asks for a code that it sends by email.
  4. Each decision is an audit event, with the score and the signals that added to it. The script prints the last five.
  5. A CAPTCHA protects sign-up and the request for a magic link from automated use.

Before you start​

Turn on the risk engine. It has no Admin API.

  1. In the portal, open Adaptive security.
  2. Turn on Enable the adaptive security engine.
  3. Keep the thresholds and the High-risk action, Challenge with MFA, for a first test.
  4. Click Save changes.

The signals of every plan are Login velocity and Failed login detection. New browser, new country, impossible travel and the other signals need an add-on. Check that your plan includes the risk signals that you use in the plans matrix.

VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
LUMOAUTH_API_KEYAn API key with the scopes admin:settings:read, admin:settings:write and admin:audit:read.
NO_MFA_ACTIONOptional. What happens when a person without a second factor signs in at risk: allow, prompt, email or block. The default of the script is email.

Code​

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The script ran against an organization with the engine turned on. A first sign-in from a new browser was permitted, and a sign-in after three wrong passwords was challenged with a code by email. The CAPTCHA steps were not carried out.

sign-in/adaptive-mfa/cli/adaptive.sh
#!/bin/sh
# Chooses what happens when a person without a second factor signs in at risk,
# and prints the last decisions of the risk engine.
#
# sh sign-in/adaptive-mfa/cli/adaptive.sh
#
# The script needs the lumo CLI and jq.
set -eu

# The CLI reads its own three variables. With them it needs no `lumo login`.
export LUMO_BASE_URL="$LUMOAUTH_URL" LUMO_ORG="$LUMOAUTH_ORG_ID" LUMO_API_KEY="$LUMOAUTH_API_KEY"

# allow, prompt, email or block. With email, LumoAuth asks for a code that it sends by email.
lumo settings update auth --set no_mfa_action="${NO_MFA_ACTION:-email}" > /dev/null
lumo settings get auth -o json | jq -r '"risky sign-in without a second factor: \(.data.no_mfa_action)"'
lumo mfa policy get -o json | jq -r '"MFA requirement: \(.data.requirement)"'

# Each scored sign-in is an audit event. Its details hold the decision, the score and the signals.
for id in $(lumo api GET /audit-logs -Q eventType=adaptive_auth.decision -Q limit=5 -o json | jq -r '.data[].id'); do
lumo logs get "$id" -o json | jq -r '.data | "\(.createdAt) \(.context.decision) score \(.context.risk_score) \(.context.signals | join(" "))"'
done
sh sign-in/adaptive-mfa/cli/adaptive.sh

The script needs the lumo CLI and jq.

Check the result​

Sign in once through the hosted page of an application: the first sign-in is permitted. Then type a wrong password three times, and sign in with the right one. LumoAuth asks for a code by email before it lets the person in. Run the script again:

Output
risky sign-in without a second factor: email
MFA requirement: risk_based
2026-11-27T18:34:59+00:00 challenge score 65 login_velocity failed_logins
2026-11-27T18:31:59+00:00 permit score 30 device_fingerprint
  • In the portal, Audit logs shows the same entries as adaptive_auth.decision. The details of an entry hold the decision, the score, the signals and the location.
  • With NO_MFA_ACTION=block, the risky sign-in is refused. With allow, it goes through and is recorded.
  • A person who has a second factor is asked for it at a risky sign-in, whatever this setting is.

Add a CAPTCHA​

  1. In the portal, open Integrations. Under Risk & bot protection, click Configure on the card of your provider: Cloudflare Turnstile, hCaptcha or reCAPTCHA Enterprise.
  2. Turn on Enable CAPTCHA, choose the Provider, and enter the Site key and the Secret key of your account at the provider.
  3. Under Placements, keep Sign-up and turn on Magic link. Sign-in and Forgot password are on as well, by default.
  4. Click Save configuration. Live preview & verify test then shows the widget with your site key.

A sign-in card of your own that sends magic links with @lumoauth/react passes the token of the widget as the third argument: sendMagicLink(email, returnTo, { captchaToken }). Without a token, LumoAuth sends no email and answers captcha_required, which useMagicLink() returns as errorCode. A token that the provider refuses gives captcha_failed. The hosted pages show the widget by themselves.

Limits​

  • The thresholds, the high-risk action and the signals are set in the portal only. A threshold can be changed only with the add-on.
  • A sign-in at 95 or more is always refused.
  • A trusted device does not skip the second factor at medium or high risk.
  • Passkey sign-in is never asked for a CAPTCHA.