Skip to main content

gdmty_django_recaptcha_enterprise

Library for Django that implements Google's reCaptcha Enterprise

This library is a draft but it works. Was made because there is no library for Django that implements Google's reCaptcha Enterprise. But now this library provides a way to verify tokens from reCaptcha Enterprise.

Installation:

pip install gdmty-django-recaptcha-enterprise

Usage:

In settings.py:

# import service_account from google.oauth2 and instanciate a Credentials object from your service account file 
from google.oauth2 import service_account

# put 'gdmty_django_recaptcha_enterprise' in INSTALLED_APPS
INSTALLED_APPS = [
    ...,
    'gdmty_django_recaptcha_enterprise',
    ...
]

# Set the following variables 
RECAPTCHA_ENTERPRISE_PROJECT_ID = 'your-project-id'

RECAPTCHA_ENTERPRISE_SITE_KEY_VERIFY = 'your-site-key' # This one is the site key for usage with seamless verification with the reCaptcha Enterprise API withouth user interaction
RECAPTCHA_ENTERPRISE_SITE_KEY_CHALLENGE = 'your-site-key' # This one is the site key for usage with challenge verification with the reCaptcha Enterprise API with user interaction
RECAPTCHA_ENTERPRISE_BYPASS_TOKEN = 'your-bypass-token' # Optional, only for debug and development usage. For production must be False. When DEBUG=False this must be False too or will not pass assesments never.

RECAPTCHA_CREDENTIALS_SERVICE_ACCOUNT = your-service-account
credentials = service_account.Credentials.from_service_account_info(RECAPTCHA_CREDENTIALS_SERVICE_ACCOUNT)
RECAPTCHA_ENTERPRISE_SERVICE_ACCOUNT_CREDENTIALS = credentials

# from_service_account_info() is a method from Credentials class that creates a Credentials object from a service account from a dictionary. You can use a json file with the service account info and load it with json.load to get the dictionary. or use from_service_account_file() method from Credentials class to load the json file and get the Credentials object directly.

In your code:

# import assess_token from gdmty_django_recaptcha_enterprise.recaptcha, then you can use it to assess tokens where you need it. In this excample we show a hypothetical view that receives a token from a POST request.
# You can use the decorator requires_recaptcha to verify the token before the view is executed.

from gdmty_django_recaptcha_enterprise.recaptcha import RecaptchaEnterprise
from gdmty_django_recaptcha_enterprise.decorators import requires_recaptcha
from django.conf import settings


recaptcha = RecaptchaEnterprise(
    settings.RECAPTCHA_ENTERPRISE_PROJECT_ID, 
    settings.RECAPTCHA_ENTERPRISE_SITE_KEY_VERIFY, 
    settings.RECAPTCHA_ENTERPRISE_SERVICE_ACCOUNT_CREDENTIALS)

# each time you need to assess a token you can use the assess_token method from the recaptcha object, can be used from this decorator using the action parameter to assess.
# When the decorator is used, the decorator handles de request to get the token from the request and assess it, if the token is valid the view is executed, if not, the view is not executed and a 403 response is returned.
# 
@requires_recaptcha(action='action-to-verify')
def my_view(request):
    ...
    pass
    ...

Release files for gdmty-django-recaptcha-enterprise 24.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gdmty-django-recaptcha-enterprise 24.5.3
File Size Uploaded
gdmty_django_recaptcha_enterprise-24.5.3.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gdmty-django-recaptcha-enterprise 24.5.3
File Interpreter ABI Platform
gdmty_django_recaptcha_enterprise-24.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.3 kB

Release files / gdmty_django_recaptcha_enterprise-24.5.3.tar.gz

Download URL gdmty_django_recaptcha_enterprise-24.5.3.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8409351319c834db95e78081e4a8894de22aba16635a0695318e1673959a034d
BLAKE2b-256 checksum
How to use checksums
86912ca212d8c2bb587408fcc50ca49e58cb55a45580db90642f686f2bc9ecee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / gdmty_django_recaptcha_enterprise-24.5.3-py3-none-any.whl

Download URL gdmty_django_recaptcha_enterprise-24.5.3-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c9ce5eba49dc3b1cc2590e09cbe0fa43761df0f018e439320bb8eeec3b02bc1
BLAKE2b-256 checksum
How to use checksums
c80a9c1137cf0854b2ece92fe31b0fd57238edf97a10fd04a57f9f146596eb6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page