SDKs and packages

Install ReCloud Turnstile like any other dependency. The official packages render the widget, verify tokens and handle errors for you.

PackagePlatformVersion
bunowave/recloud-laravelPHP 8.1+ with Laravel 10, 11, 12 or 131.0.0
@bunowaveltd/recloudNode.js 18+, Next.js, React, Express and browsers1.0.0
recloudPython 3.8+ with Flask, Django, FastAPI and more1.0.0
Installed from ReCloud. Packages are served directly from https://recloud-turnstile.bunowave.shop/packages. No account or access token is needed. Checksums are published in checksums.txt.

Laravel

Install the package. Laravel discovers it automatically.

composer config repositories.recloud composer https://recloud-turnstile.bunowave.shop/packages/composer
composer require bunowave/recloud-laravel

Add your keys to .env:

RECLOUD_SITE_KEY=YOUR_SITE_KEY
RECLOUD_SECRET=YOUR_SECRET_KEY

Render the widget with the Blade component:

<form method="POST" action="/contact">
    @csrf
    <x-recloud theme="dark" size="flexible" />
    <button type="submit">Send</button>
</form>

The component accepts theme, size, align, accent, language, callback, error-callback and site-key. The widget script is loaded once per page.

Validate the token

Use the rule object, the string rule, the middleware or the facade. All of them reject empty, expired, reused and forged tokens.

use BunoWave\ReCloud\Rules\ReCloudRule;

$request->validate([
    'recloud-response' => ['required', new ReCloudRule()],
]);
$request->validate([
    'recloud-response' => 'required|recloud',
]);
use BunoWave\ReCloud\Http\Middleware\VerifyReCloud;

Route::post('/contact', ContactController::class)->middleware(VerifyReCloud::class);
use BunoWave\ReCloud\Facades\ReCloud;

$result = ReCloud::verify($request->input('recloud-response'), $request->ip());

if ($result->failed()) {
    abort(422, 'Verification failed');
}

Configuration

SettingDefaultDescription
RECLOUD_SITE_KEYnoneYour public site key, used by the Blade component.
RECLOUD_SECRETnoneYour secret key, used to verify tokens.
RECLOUD_URLhttps://recloud-turnstile.bunowave.shopBase URL of the ReCloud service.
RECLOUD_SEND_IPfalseSend the visitor IP so the token must match it. Enable only if your proxy setup reports real client IPs.
timeout10Seconds to wait for the verification request. Set in the published config.
fail_openfalseAccept visitors when the ReCloud service cannot be reached. Keep it off for sensitive actions.

Publish the config file with php artisan vendor:publish --tag=recloud-config.

JavaScript and Node.js

npm install https://recloud-turnstile.bunowave.shop/packages/npm/bunowaveltd-recloud-1.0.0.tgz

The package is ESM and ships TypeScript types. It has three entry points: the root for server code, /client for the browser and /react for React.

Verify on the server

import { verify } from '@bunowaveltd/recloud';

const result = await verify(token, {
  secret: process.env.RECLOUD_SECRET,
  remoteip: ip,
});

if (!result.success) {
  throw new Error('Verification failed');
}
OptionDescription
secretYour secret key. Defaults to the RECLOUD_SECRET environment variable.
remoteipOptional visitor IP. When set, it must match the IP the token was issued to.
timeoutMilliseconds before the request is aborted. Default 10000.
failOpenTreat a network failure as success. Default false.
urlBase URL of the ReCloud service. Defaults to https://recloud-turnstile.bunowave.shop.

Express middleware

import express from 'express';
import { middleware } from '@bunowaveltd/recloud';

const app = express();
app.use(express.urlencoded({ extended: false }));

app.post('/contact', middleware({ secret: process.env.RECLOUD_SECRET }), (req, res) => {
  res.send('OK');
});

Next.js route handler

import { verify } from '@bunowaveltd/recloud';

export async function POST(req) {
  const { token } = await req.json();
  const result = await verify(token, { secret: process.env.RECLOUD_SECRET });

  if (!result.success) {
    return Response.json({ error: 'Verification failed' }, { status: 400 });
  }

  return Response.json({ ok: true });
}

React component

'use client';

import { useState } from 'react';
import { ReCloud } from '@bunowaveltd/recloud/react';

export function ContactForm() {
  const [token, setToken] = useState('');

  async function submit(event) {
    event.preventDefault();
    await fetch('/api/contact', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ token }),
    });
  }

  return (
    <form onSubmit={submit}>
      <ReCloud siteKey="YOUR_SITE_KEY" theme="auto" onVerify={setToken} />
      <button disabled={!token}>Send</button>
    </form>
  );
}

The component re-renders the widget when its props change and cleans up when it unmounts. Pass a ref to call reset() or getResponse().

Plain browser

import { render } from '@bunowaveltd/recloud/client';

await render(document.querySelector('#captcha'), {
  siteKey: 'YOUR_SITE_KEY',
  onVerify: (token) => console.log(token),
});

Python

pip install https://recloud-turnstile.bunowave.shop/packages/pypi/recloud-1.0.0.tar.gz

The package has no dependencies. Result objects are truthy when verification succeeded.

from recloud import verify

result = verify(token, secret="YOUR_SECRET_KEY", remoteip=ip)

if not result:
    abort(400)
from recloud import Client

recloud = Client(secret="YOUR_SECRET_KEY", timeout=5, fail_open=False)

result = recloud.verify(token, remoteip=ip)
print(result.success, result.risk, result.error_codes)

Updates and versions

Packages follow semantic versioning. A new version appears in the registries when it is released, and your package manager picks it up the next time you update. Pin an exact version in production if you need fully reproducible builds.