Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HR/recaptcha-worker
reCAPTCHA v3 Cloudflare Worker
https://github.com/HR/recaptcha-worker
captcha captcha-recaptcha cloudflare cloudflare-worker cloudflare-workers google-recaptcha recaptcha recaptcha-api recaptcha-v3 recaptcha-verification recaptcha-worker
Last synced: 3 months ago
JSON representation
reCAPTCHA v3 Cloudflare Worker
- Host: GitHub
- URL: https://github.com/HR/recaptcha-worker
- Owner: HR
- License: mit
- Created: 2020-10-15T22:19:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-18T12:27:44.000Z (over 3 years ago)
- Last Synced: 2024-08-01T16:35:00.112Z (6 months ago)
- Topics: captcha, captcha-recaptcha, cloudflare, cloudflare-worker, cloudflare-workers, google-recaptcha, recaptcha, recaptcha-api, recaptcha-v3, recaptcha-verification, recaptcha-worker
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 38
- Watchers: 3
- Forks: 30
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cloudflare - Google reCAPTCHA verification - Handle the server-side verification of your reCAPTCHA form. (Workers / Recipes)
- awesome-cloudflare - Google reCAPTCHA verification - Handle the server-side verification of your reCAPTCHA form. (Workers / Recipes)
README
# Google reCAPTCHA v3 Cloudflare Worker
Google reCAPTCHA v3 Cloudflare Worker that handles the server-side verification of your reCAPTCHA.## Installation
This requires you to have a Cloudflare Workers account and have the Workers CLI installed. If you haven't already, follow this https://developers.cloudflare.com/workers/get-started/guide
1. Deploy it
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/HR/recaptcha-worker)
2. Set your [reCAPTCHA secret key](https://developers.google.com/recaptcha/intro) environment variable
```
$ wrangler secret put RECAPTCHA_SECRET --env recaptcha-worker
```3. Write the client-side request code (see Usage)
## Usage
### Request
From your client-side, make a `POST` request to your deployed cloudflare worker endpoint with the header field `g-recaptcha` set to your reCAPTCHA token.
Like so:
```Javascript
$.ajax({
type: 'POST',
url: 'https://recaptcha-worker.YOUR-SUBDOMAIN.workers.dev',
headers: { 'g-recaptcha': YOUR_RECAPTCHA_TOKEN },
error: function (res, status, error) {
if (res.status === 400) {
// Verification failed
} else {
// An error occured
console.log(res.responseText)
}
},
success: function (res) {
// Verification successful
// POST the form data to your backend or something
}
})
```### Response
If the verification request succeeds, you'll get a `202` HTTP status code response with the body `reCAPTCHA passed`.
If the verification request fails, you will get `400` HTTP status code response with the body `reCAPTCHA failed`.
Otherwise, for any other error, you will get `500` HTTP status code response with the body being the error stack.