A lightweight server implementation for handling reCAPTCHA verification in your applications.
- Verify reCAPTCHA tokens securely.
- Easy integration with backend services.
- Configurable for different reCAPTCHA versions.
-
Clone the repository:
git clone https://github.com/yourusername/recaptcha-server.git cd recaptcha-server -
Install dependencies:
make tidy
-
Configure environment variables: Create a
.envfile and set the following:RECAPTCHA_SECRET_KEY="" # Required RECAPTCHA_FRONTEND="" # Optional, but HIGHLY recommended for production use,can be any valid URL (e.g., http://localhost:3000), defaults to "*" RECAPTCHA_TIMEZONE="" # Optional, can be any valid timezone string (See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) RECAPTCHA_PORT="" # Optional, defaults to 8080 LOG_LEVEL="" # Optional, defaults to "info" ("debug", "info", "warn", "error", "fatal")
Warning
You should only use .env files in development. In production, use environment variables directly.
Start the server:
make devSend a POST request to verify a token:
POST /verify
Content-Type: application/json
{
"token": "your-recaptcha-token"
}For production, you can build the server binary or use the Docker image. There is a publicly available Docker image on GitHub Container Registry. However, it is recommended to build the image yourself to ensure security and integrity. You can build the Docker image using the following command:
make buildRECAPTCHA_SECRET_KEY: Your reCAPTCHA secret key.RECAPTCHA_FRONTEND: Optional, but highly recommended for production use. Can be any valid URL (e.g., http://localhost:3000), defaults to "*".
RECAPTCHA_TIMEZONE: Can be any valid timezone string (See List of tz database time zones).RECAPTCHA_PORT: Defaults to8080.LOG_LEVEL: Defaults toinfo. Can be set todebug,info,warn,error, orfatal.
The only endpoint available is /verify, which accepts a POST request with the following JSON body:
{
"token": "your-recaptcha-token"
}- 200 OK: Verification successful.
- 400 Bad Request: Invalid or missing token. (See response body for details)
Contributions are welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License.