Skip to content

Protect sign-up with reCAPTCHA

A realm’s bot protection puts a challenge in front of the requests that anyone can make without signing in. With Google reCAPTCHA turned on, the sign-in pages get a token from Google for each of those requests, and the identity server verifies the token with Google before it does anything else, including its own rate limits.

The challenge guards four requests:

  • signing up with a password;
  • requesting a magic link;
  • resending a magic link;
  • resending a one-time code.

Signing in with a password isn’t challenged.

  • Identity server 1.89.0 or later. Google’s test key needs 1.91.1 or later.
  • Login pages 0.33.0 or later. An install that serves its own login pages image must be on that version, or the pages show no challenge and every guarded request is refused.
  • Console 0.55.0 or later, awctl 0.45.1 or later, or Terraform provider 0.35.0 or later.
  • A reCAPTCHA key from Google, with its site key and its legacy secret key. The identity server verifies tokens with the legacy secret key and uses no Google Cloud credential.
  • The sign-in hostname allowed on the key. The identity server refuses a token that Google reports as solved on any hostname other than the one the request came in on.
  • Billing turned on for the key’s Google Cloud project. See When verification fails.

The realm must name the type of the key, as you created it at Google.

Key typeSettingWhat the person sees
Checkbox (v2)CHECKBOXThe reCAPTCHA checkbox widget on the form. The form can’t be sent until the widget yields a token.
Score (v3)SCORENo widget. The page asks Google for a token when the form is sent, and shows the notice “This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.”

With a score key, Google rates each request from 0 to 1. A request that scores below the realm’s lowest score is refused like a failed check. The default lowest score is 0.5.

The site key is public and goes on the realm. The secret key is never a plain field: you store it as a tenant secret, and the realm names that secret.

  1. In the console, go to Realms and open the realm.
  2. Open the Settings tab.
  3. Open Protection against abuse.
  4. Under Bot protection, in Challenge, select Always.
  5. In Provider, select Google reCAPTCHA.
  6. In Site key, enter the key’s site key.
  7. In Secret key, select the tenant secret that holds the key’s legacy secret key. To store it now, click Create a secret, enter a Display name and the secret key, and then click Create and select.
  8. In Key type, select Checkbox (v2) or Score (v3).
  9. For a score key, optionally enter a value from 0 to 1 in Lowest score let through. Blank means 0.5.
  10. Click Save. The row then reads Bot check on.
  1. Store the secret key as a tenant secret. The material is read from standard input, never from a flag:

    Terminal window
    printf %s "$RECAPTCHA_SECRET_KEY" | awctl identity secrets create \
    --tenant-id TENANT_ID --display-name "reCAPTCHA secret key" --data-file=-
  2. Set the realm’s bot_protection:

    Terminal window
    awctl identity realms update REALM_ID --tenant-id TENANT_ID \
    --config '{"bot_protection": {"mode": "ALWAYS", "provider": "RECAPTCHA",
    "site_key": "SITE_KEY", "secret_ref": {"name": "tenants/TENANT_ID/secrets/SECRET_ID"},
    "recaptcha_key_type": "SCORE", "min_score": 0.7}}'

Replace TENANT_ID with the tenant’s ID (t-…), REALM_ID with the realm’s ID (r-…), SITE_KEY with the key’s site key, and SECRET_ID with the ID of the secret you created (s-…).

resource "authwise_secret" "recaptcha" {
display_name = "reCAPTCHA secret key"
payload_wo = var.recaptcha_secret_key
payload_wo_version = 1
}
data "authwise_realm_config" "customers" {
bot_protection = {
mode = "ALWAYS"
provider = "RECAPTCHA"
site_key = "SITE_KEY"
secret_ref = { name = authwise_secret.recaptcha.name }
recaptcha_key_type = "SCORE"
min_score = 0.7
}
}
resource "authwise_realm" "customers" {
display_name = "Customers"
config = data.authwise_realm_config.customers.json
}

Replace SITE_KEY with the key’s site key. payload_wo is a write-only argument, which needs Terraform 1.11 or later. To send a new secret key, change payload_wo and raise payload_wo_version.

ConsoleAPI and TerraformMeaning
ChallengemodeOFF, the default, or ALWAYS. ADAPTIVE is reserved and refused.
ProviderproviderRECAPTCHA for Google reCAPTCHA.
Site keysite_keyThe key’s public site key. The sign-in pages use it to load reCAPTCHA.
Secret keysecret_refThe tenant secret that holds the key’s legacy secret key.
Key typerecaptcha_key_typeCHECKBOX or SCORE. Required for reCAPTCHA.
Lowest score let throughmin_scoreFor a score key only, from 0 to 1. Unset means 0.5.
Time out aftertimeoutHow long one verification can take. Unset means 3 seconds.
When the verifier does not answerfail_modeCLOSED, the default, refuses the request. OPEN lets it through.

A write that can’t work as written is refused, and the message names every problem: ALWAYS with no provider, a missing site key or secret, a missing key type, or a lowest score on anything but a score key.

A request fails the check when it carries no token, when Google refuses the token, when the token was solved on another hostname, or when a score key’s score is below the realm’s lowest score.

RequestWhat the person seesWhat is recorded
Sign-upThe message “verification failed; complete the challenge and try again”. No account is created.An authn.signup event, denied, with the reason bot_suspected.
Magic-link request or resendThe same answer as a request that was sent. Nothing is sent.A security.rate_limited event, denied, with the limiter botcheck and the reason bot_suspected.
One-time code resendNo code is sent.A security.rate_limited event, denied, with the limiter botcheck and the reason bot_suspected.

If Google’s script doesn’t load in the person’s browser, the form shows “We couldn’t load the check that keeps this form safe. Reload the page to try again.”

If the identity server can’t reach Google, or Google doesn’t answer within the timeout, the result depends on When the verifier does not answer:

  • Fail closed, the default, refuses the request, with the reason upstream_unavailable.
  • Fail open lets the request through.

A Google Cloud project without billing that passes Google’s free monthly quota answers every token as passed. The identity server treats that answer as a failed check, whatever the fail mode, and records the reason bot_vendor_over_quota. Every guarded request then fails until you turn on billing for the project.

  1. Open the realm’s sign-up page in a private browser window. For a checkbox key, the form shows the reCAPTCHA widget. For a score key, the form shows the reCAPTCHA notice under its fields.
  2. Sign up with a new address. The account is created.
  3. In the console, go to Activity. A refused sign-up appears as a denied authn.signup event with the reason bot_suspected. A sign-up that passed the check has no such event.

To exercise the pages without a real check, a realm can use Google’s published test site key, 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI, with Google’s published test secret.

SymptomCause and fix
Every sign-up fails with “verification failed; complete the challenge and try again”The identity server’s log says why Google’s answer was refused. A hostname that isn’t the sign-in hostname means the key doesn’t allow that hostname. invalid-input-secret among the error codes means the tenant secret doesn’t hold the key’s legacy secret key. A score below the floor means the lowest score is too high for your traffic.
Every guarded request fails, and events carry bot_vendor_over_quotaThe key’s Google Cloud project is past its free quota. Turn on billing for the project.
The form shows no reCAPTCHA, and guarded requests are refusedThe login pages are older than 0.33.0. Upgrade them.
Saving is refused with bot_protection.recaptcha_key_type is required for recaptchaSet the key type to CHECKBOX or SCORE.
Saving is refused with bot_protection.min_score applies only to a reCAPTCHA SCORE keyRemove the lowest score, or set the key type to SCORE.
Events carry upstream_unavailableThe identity server couldn’t reach Google within the timeout. Check its outbound access to www.google.com.