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.0.5a2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

reflex_google_recaptcha_v2-0.0.5a2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file reflex_google_recaptcha_v2-0.0.5a2.tar.gz.

File metadata

File hashes

Hashes for reflex_google_recaptcha_v2-0.0.5a2.tar.gz
Algorithm Hash digest
SHA256 a21292a45b4a40b2095f716491b9ebf663735c88df6a7117f2e92ca400b4108b
MD5 1f621eeb1e96f861f8bde32e6d7e816f
BLAKE2b-256 93373d2ba6c615321c61b001699cb047b55515870cb5d08e4dd5647e1da4f5a7

See more details on using hashes here.

File details

Details for the file reflex_google_recaptcha_v2-0.0.5a2-py3-none-any.whl.

File metadata

File hashes

Hashes for reflex_google_recaptcha_v2-0.0.5a2-py3-none-any.whl
Algorithm Hash digest
SHA256 327e5e6fb5d2042760431ef55c6ba2a7d50d64cc08ba5106e5516328c8f04edb
MD5 9018fac05eb0730fe12ded84e743c948
BLAKE2b-256 8dd6b950f3be9527c9495f3d081fc82819f7f9ea686913afc4fa3eff9d814e3e

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