Metadata-Version: 2.5
Name: entirius-django-captcha
Version: 2.0.1
Summary: reCAPTCHA verification for Entirius: a view decorator backed by per-channel service configuration
Project-URL: Homepage, https://docs.entirius.com/
Project-URL: Documentation, https://docs.entirius.com/
Project-URL: Repository, https://github.com/entirius/entirius-django-captcha
Project-URL: Changelog, https://github.com/entirius/entirius-django-captcha/releases
Project-URL: Issues, https://github.com/entirius/entirius-django-captcha/issues
Author: Entirius
License-Expression: MPL-2.0
License-File: LICENSE
Keywords: captcha,django,ecommerce,entirius,recaptcha,security
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Requires-Python: >=3.11
Requires-Dist: django>=4.0.0
Requires-Dist: entirius-django-utils>=2.0.0
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Requires-Dist: pytest-django; extra == 'test'
Description-Content-Type: text/markdown

# entirius-django-captcha

A Django module for reCAPTCHA verification in Entirius, the open-source modular ecommerce platform. It provides a
view decorator that checks the token of a request against the Google reCAPTCHA API, with one configuration per sales
channel.

[![PyPI](https://img.shields.io/pypi/v/entirius-django-captcha.svg)](https://pypi.org/project/entirius-django-captcha/)
[![Python](https://img.shields.io/pypi/pyversions/entirius-django-captcha.svg)](https://pypi.org/project/entirius-django-captcha/)
[![License: MPL-2.0](https://img.shields.io/badge/license-MPL--2.0-blue.svg)](https://github.com/entirius/entirius-django-captcha/blob/develop/LICENSE)

## What it does

- Protects any Django view with the `verify_recaptcha` decorator.
- Stores reCAPTCHA configuration as `Service` records: global or per sales channel, with a secret key and an active
  flag.
- Picks the active service of the request's channel first and falls back to the global one.
- Lets requests through when no active service is configured, so the check can be switched on per environment.

## Installation

```shell
uv add entirius-django-captcha
pip install entirius-django-captcha
```

```python
INSTALLED_APPS = [
    ...
    "django_utils",
    "django_captcha",
]

# urls.py
urlpatterns = [
    path("", include("django_captcha.urls")),
]
```

Optional settings: `CAPTCHA_TOKEN_HEADER_NAME` (default `X-Recaptcha-Token`), `CAPTCHA_URL` (default: the Google
siteverify endpoint), `CAPTCHA_VERIFY_TIMEOUT` (seconds, default `5`), `API_BASE_URL` (default `api`); reference in
https://github.com/entirius/entirius-django-captcha/blob/develop/AGENTS.md (section Architecture).

## Quick start

```python
from django_captcha.output.decorators import verify_recaptcha


@verify_recaptcha
def my_view(request):
    ...
```

The decorator reads the token from the `X-Recaptcha-Token` request header and raises a validation error when the
token is missing or rejected, or the verification request fails or times out. Create a `Service` record with the
secret key in the Django admin to switch it on.

## Requirements

- Python 3.11 or newer, Django 4.0 or newer.
- Entirius packages pulled in: `entirius-django-utils`.

## Documentation

- Entirius documentation: https://docs.entirius.com/
- Releases: https://github.com/entirius/entirius-django-captcha/releases

## Part of Entirius

This module runs inside the Entirius backend service (Volkanos), where public endpoints of other modules use it.

- Backend service: https://github.com/entirius/entirius-service-volkanos
- Docker harness: https://github.com/entirius/entirius-zeno
- Sibling modules: https://github.com/entirius/entirius-django-utils,
  https://github.com/entirius/entirius-django-accounts

## Development

```shell
make install     # sync dependencies (uv)
make check       # lint + format check (ruff)
make test        # test suite (pytest + pytest-django)
```

Development and agent instructions: https://github.com/entirius/entirius-django-captcha/blob/develop/AGENTS.md

## License

Mozilla Public License 2.0 (MPL-2.0) — see https://github.com/entirius/entirius-django-captcha/blob/develop/LICENSE.
