メインコンテンツまでスキップ

Friendly Captcha

Friendly Captcha v2 is a privacy-first, GDPR-compliant CAPTCHA service based on proof-of-work without visual puzzles. This guide walks you through setting up Friendly Captcha with Logto.

Prerequisites​

  • A Friendly Captcha account

Get the sitekey and API key​

  1. Log in to the Friendly Captcha dashboard and go to Applications.
  2. Click + New Application and select v2.
  3. If you restrict allowed origins on the application, add your Logto endpoint domain (e.g., https://[tenant-id].logto.app).
  4. Keep the global endpoint (global.frcapi.com) enabled unless you restrict the sitekey to the EU endpoint (eu.frcapi.com, available on Advanced and Enterprise plans), and copy the Sitekey (starts with FC).
  5. Open API Keys in the dashboard, create a new API key, and copy it.

Configure Logto​

  1. Go to Console > Security > CAPTCHA, select Friendly Captcha, and enter the Site key and API key. Keep API endpoint as Global, or choose EU if your sitekey is restricted to the EU endpoint.
  2. Alternatively, configure it via the Management API (PUT /api/captcha-provider). apiEndpoint is optional and accepts "global" (default) or "eu":
{
"config": {
"type": "FriendlyCaptcha",
"siteKey": "<siteKey>",
"secretKey": "<apiKey>",
"apiEndpoint": "global"
}
}

Bring your UI​

If you use Bring your UI, Logto can't inject or run Friendly Captcha in your custom frontend automatically. After enabling CAPTCHA in Logto Console, your custom UI must load @friendlycaptcha/sdk, mount the widget, wait for the completion token, and send it to the Experience API.

Install the Friendly Captcha v2 SDK in your custom UI project:

npm install @friendlycaptcha/sdk

Add a container for the widget:

<div id="friendly-captcha-container"></div>

Mount the widget with FriendlyCaptchaSDK, wait for frc:widget.complete to read event.detail.response, pass that single-use token as captchaToken in PUT /api/experience, and reset via widget.reset() after consuming the token so retries obtain a fresh token:

import { FriendlyCaptchaSDK } from '@friendlycaptcha/sdk';

const sdk = new FriendlyCaptchaSDK();
const element = document.querySelector('#friendly-captcha-container');

const widget = sdk.createWidget({
element,
sitekey: '<siteKey>',
// Set to 'eu' if you chose the EU API endpoint in Logto.
apiEndpoint: 'global',
});

const getCaptchaToken = () => {
if (widget.getState() === 'completed') {
return Promise.resolve(widget.getResponse());
}

return new Promise((resolve, reject) => {
const cleanup = () => {
widget.removeEventListener('frc:widget.complete', onComplete);
widget.removeEventListener('frc:widget.error', onError);
};

const onComplete = (event) => {
cleanup();
resolve(event.detail.response);
};

const onError = (event) => {
cleanup();
reject(new Error(event.detail.error.detail || event.detail.error.code));
};

widget.addEventListener('frc:widget.complete', onComplete);
widget.addEventListener('frc:widget.error', onError);

if (['init', 'reset', 'unactivated'].includes(widget.getState())) {
widget.start();
}
});
};

// Before starting the interaction, obtain the single-use token:
const captchaToken = await getCaptchaToken();

try {
await fetch('/api/experience', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
interactionEvent: 'SignIn',
captchaToken,
}),
});
} finally {
// Tokens are single-use; reset the widget so retries obtain a fresh token.
widget.reset();
}

Enable CAPTCHA​

Remember to enable CAPTCHA bot protection after you have set up the CAPTCHA provider.

Go to the Security page, find the CAPTCHA tab, and switch on the toggle button of "Enable CAPTCHA".