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.5a1.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.5a1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for reflex_google_recaptcha_v2-0.0.5a1.tar.gz
Algorithm Hash digest
SHA256 41c075f24926b38b30c302dc45310d5806f0860f48c2096b2417ec647806f210
MD5 f331fa5cbb36af099effa08463107a84
BLAKE2b-256 abfe9e077df58a500fd771eaa4aabb293ac6e85678f8d04bb06b1565f339d468

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for reflex_google_recaptcha_v2-0.0.5a1-py3-none-any.whl
Algorithm Hash digest
SHA256 98ebb2d9a770e04ec624b53e44f28e1a85f6d4346562efe70ed2bfbffb4c9644
MD5 706e80d63dcea7bb412e1e4fa8cade38
BLAKE2b-256 a09ab8a38e1d405205bd51f0c22479b91f97cbcd022c8fe31e12124487cb6756

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