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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for reflex_google_recaptcha_v2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5897e8109591b7c24db6591642c29efbe9cf7100d0bae26fa594c9b7f87542e1
MD5 c866aa2d463f16dc97d89b314b63c0d6
BLAKE2b-256 52ad772c2975c92c3b16864c1fd995edacb998c70c266671668cc90863a93447

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for reflex_google_recaptcha_v2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37b999cf9864e4ff204c05093adea644ea5a19d146bf913230508d2030b133d7
MD5 9d554c0ce477bcdb7df177bbc502944a
BLAKE2b-256 ab9670a527e13612e9f871c8411d2719c7b133c68ead15bdafea89735df0ca02

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