Skip to main content

Google ReCAPTCHA v2 Integration

Project description

google-recaptcha-v2

A Reflex custom component google-recaptcha-v2.

Installation

pip install reflex-google-recaptcha-v2

Usage

Set your site key and secret key in your environment variables.

export RECAPTCHA_SITE_KEY="your-site-key"
export RECAPTCHA_SECRET_KEY="your-secret-key"

Alternatively, you can set the keys via python functions as seen in the demo app.

These keys can be obtained at Google's Recaptcha Portal. To access the secret key, which is required, go to the Integration tab and select "Use legacy key" or "I'm integrating with a third party library".

Place the Recaptcha component

import reflex as rx

from reflex_google_recaptcha_v2 import google_recaptcha_v2

def index():
    return rx.vstack(
        ...,
        google_recaptcha_v2(),
    )

Verify the Recaptcha response

Before taking actions on the backend, you should verify that the user browser has passed validation of the token.

This value will be set for the specific tab that has completed validation and persists for the lifetime of the Reflex session (until the tab is closed).

import reflex as rx

from reflex_google_recaptcha_v2 import GoogleRecaptchaV2State


class MyState(rx.State):
    form_error: str

    async def handle_submit(self, form_data):
        ...
        recaptcha_state = await self.get_state(GoogleRecaptchaV2State)
        if not recaptcha_state.token_is_valid:
            self.form_error = "Invalid recaptcha. Are you a robot?"
            return

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reflex_google_recaptcha_v2-0.1.0.post1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file reflex_google_recaptcha_v2-0.1.0.post1.tar.gz.

File metadata

  • Download URL: reflex_google_recaptcha_v2-0.1.0.post1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for reflex_google_recaptcha_v2-0.1.0.post1.tar.gz
Algorithm Hash digest
SHA256 43a22f2a35e6c7498ce4f2f2630281528d3888338652f2afd125414839b0ef8c
MD5 3cff1e8735e6942d32ccc26adf10f1d4
BLAKE2b-256 b414b69929d6c553a25a32ee36eb38f6db7ea15a046c166eed39d39e52cdf7cd

See more details on using hashes here.

File details

Details for the file reflex_google_recaptcha_v2-0.1.0.post1-py3-none-any.whl.

File metadata

  • Download URL: reflex_google_recaptcha_v2-0.1.0.post1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for reflex_google_recaptcha_v2-0.1.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 12264cfc6e20789d3ec68440caf7a2c07fb44ef479e42f16ee5b078b266830ec
MD5 b7530c5d6898cdc30bdf4f32a05333d5
BLAKE2b-256 a0aed93c2e6a7a50fdd0b8e739de4d392a19f9d6191a0a25ef91eddcb8bb6097

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page