Socket
Book a DemoInstallSign in
Socket

turnstile-validator

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turnstile-validator

A validator for Cloudflare Turnstile tokens

1.0.0
latest
npmnpm
Version published
Weekly downloads
76
1800%
Maintainers
0
Weekly downloads
 
Created
Source

turnstile-validator

A TypeScript validator for Cloudflare Turnstile tokens.

Installation

npm install turnstile-validator

Usage

import TurnstileValidator from "turnstile-validator";

const validator = new TurnstileValidator("your_secret_key");

async function validateToken(token: string, clientIp?: string) {
  try {
    const result = await validator.validate(token, clientIp);
    console.log(result);
    // { success: true, challenge_ts: '2023-01-01T00:00:00Z', hostname: 'example.com', ... }
  } catch (error) {
    console.error("Validation failed:", error.message);
  }
}

validateToken("user_response_token", "127.0.0.1");

API

new TurnstileValidator(secretKey: string)

Creates a new validator instance.

  • secretKey: Your Cloudflare Turnstile secret key

validator.validate(token: string, clientIp?: string): Promise<TurnstileResponse>

Validates a Turnstile token.

  • token: The user response token from the Turnstile widget
  • clientIp: (Optional) The IP address of the user

Returns a Promise that resolves to the Cloudflare API response.

TurnstileResponse Interface

interface TurnstileResponse {
  success: boolean;
  challenge_ts: string;
  hostname: string;
  error_codes?: string[];
  action?: string;
  cdata?: string;
}

Development

  • Clone the repository
  • Install dependencies: npm install
  • Run tests: npm test
  • Build the package: npm run build

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

cloudflare

FAQs

Package last updated on 10 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.