# Django REST hCAPTCHA
**Django REST hCAPTCHA v2 and v3 field serializer**
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![PyPI](https://img.shields.io/pypi/v/drf-hcaptcha)](https://pypi.org/project/drf-hcaptcha/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/drf-hcaptcha)](https://pypi.org/project/drf-hcaptcha/)
## Requirements
* Python: 3.7, 3.8, 3.9, 3.10, 3.11
* Django: 3.2, 4.0, 4.1, 4.2
* DRF: 3.11, 3.12, 3.13, 3.14
## Installation
1. Install with `pip install drf-hcaptcha`
2. Add `"drf_hcaptcha"` to your `INSTALLED_APPS` settings.
3. Set in settings `DRF_HCAPTCHA_SECRET_KEY`
```python
INSTALLED_APPS = [
...,
"drf_hcaptcha",
...,
]
...
DRF_HCAPTCHA_SECRET_KEY = "YOUR SECRET KEY"
```
## Usage
```python
from rest_framework.serializers import Serializer
from drf_hcaptcha.fields import HCaptchaV2Field
class V2Serializer(Serializer):
hcaptcha = HCaptchaV2Field()
...
```
## Settings
`DRF_HCAPTCHA_SECRET_KEY` - set your hCAPTCHA secret key. Type: str.
`DRF_HCAPTCHA_DEFAULT_V3_SCORE` - by default: `0.5`. Type: float.
`DRF_HCAPTCHA_ACTION_V3_SCORES` - by default: `{}`. Type: dict. You can define specific score for each action e.g. `{"login": 0.6, "feedback": 0.3}`
`DRF_HCAPTCHA_DOMAIN` - by default: `api.hcaptcha.com`. Type: str.
`DRF_HCAPTCHA_PROXY` - by default: `{}`. Type: dict. e.g. `{'http': 'http://127.0.0.1:8000', 'https': 'https://127.0.0.1:8000'}`
`DRF_HCAPTCHA_VERIFY_REQUEST_TIMEOUT` - by default: `10`. Type: int.
### Priority of secret_key value
1. settings `DRF_HCAPTCHA_SECRET_KEY`
2. the argument `secret_key` of field
3. request.context["hcaptcha_secret_key"]
## hCAPTCHA v3
Validation is passed if the score value returned by Google is greater than or equal to required score.
Required score value: `0.0 - 1.0`
### Priority of score value
If not defined or zero in current item then value from next item.
1. Value for action in settings `DRF_HCAPTCHA_ACTION_V3_SCORES`
2. Value in argument `required_score` of field
3. Default value in settings `DRF_HCAPTCHA_DEFAULT_V3_SCORE`
4. Default value `0.5`
Raw data
{
"_id": null,
"home_page": "https://github.com/pysashapy/drf-hcaptcha",
"name": "drf-hcaptcha",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "django,drf,rest,django-rest-framework,hCAPTCHA,hCAPTCHA v2,hCAPTCHA v3",
"author": "Alexander I",
"author_email": "sasha.2000ibr@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/34/32/151023195c0dae83a5c747779fca528583694f9ad199cead61cf0e22f702/drf-hcaptcha-1.0.1.tar.gz",
"platform": null,
"description": "# Django REST hCAPTCHA\r\n\r\n**Django REST hCAPTCHA v2 and v3 field serializer**\r\n\r\n\r\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\r\n[![PyPI](https://img.shields.io/pypi/v/drf-hcaptcha)](https://pypi.org/project/drf-hcaptcha/)\r\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/drf-hcaptcha)](https://pypi.org/project/drf-hcaptcha/)\r\n\r\n## Requirements\r\n\r\n* Python: 3.7, 3.8, 3.9, 3.10, 3.11\r\n* Django: 3.2, 4.0, 4.1, 4.2\r\n* DRF: 3.11, 3.12, 3.13, 3.14\r\n\r\n## Installation\r\n1. Install with `pip install drf-hcaptcha`\r\n2. Add `\"drf_hcaptcha\"` to your `INSTALLED_APPS` settings.\r\n3. Set in settings `DRF_HCAPTCHA_SECRET_KEY`\r\n\r\n```python\r\nINSTALLED_APPS = [\r\n ...,\r\n \"drf_hcaptcha\",\r\n ...,\r\n]\r\n\r\n...\r\n\r\nDRF_HCAPTCHA_SECRET_KEY = \"YOUR SECRET KEY\"\r\n```\r\n\r\n## Usage\r\n\r\n```python\r\nfrom rest_framework.serializers import Serializer\r\nfrom drf_hcaptcha.fields import HCaptchaV2Field\r\n\r\n\r\nclass V2Serializer(Serializer):\r\n hcaptcha = HCaptchaV2Field()\r\n ...\r\n\r\n```\r\n\r\n## Settings\r\n\r\n`DRF_HCAPTCHA_SECRET_KEY` - set your hCAPTCHA secret key. Type: str.\r\n\r\n`DRF_HCAPTCHA_DEFAULT_V3_SCORE` - by default: `0.5`. Type: float.\r\n\r\n`DRF_HCAPTCHA_ACTION_V3_SCORES` - by default: `{}`. Type: dict. You can define specific score for each action e.g. `{\"login\": 0.6, \"feedback\": 0.3}`\r\n\r\n`DRF_HCAPTCHA_DOMAIN` - by default: `api.hcaptcha.com`. Type: str.\r\n\r\n`DRF_HCAPTCHA_PROXY` - by default: `{}`. Type: dict. e.g. `{'http': 'http://127.0.0.1:8000', 'https': 'https://127.0.0.1:8000'}`\r\n\r\n`DRF_HCAPTCHA_VERIFY_REQUEST_TIMEOUT` - by default: `10`. Type: int.\r\n\r\n### Priority of secret_key value\r\n\r\n1. settings `DRF_HCAPTCHA_SECRET_KEY`\r\n2. the argument `secret_key` of field\r\n3. request.context[\"hcaptcha_secret_key\"]\r\n\r\n## hCAPTCHA v3\r\n\r\nValidation is passed if the score value returned by Google is greater than or equal to required score.\r\n\r\nRequired score value: `0.0 - 1.0`\r\n\r\n### Priority of score value\r\n\r\nIf not defined or zero in current item then value from next item.\r\n\r\n1. Value for action in settings `DRF_HCAPTCHA_ACTION_V3_SCORES`\r\n2. Value in argument `required_score` of field\r\n3. Default value in settings `DRF_HCAPTCHA_DEFAULT_V3_SCORE`\r\n4. Default value `0.5`\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django rest framework hcaptcha field serializer.",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/pysashapy/drf-hcaptcha"
},
"split_keywords": [
"django",
"drf",
"rest",
"django-rest-framework",
"hcaptcha",
"hcaptcha v2",
"hcaptcha v3"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3432151023195c0dae83a5c747779fca528583694f9ad199cead61cf0e22f702",
"md5": "bbc366abcf587feb04e280922a787d0d",
"sha256": "039748c3f31d19f4a9be4c23ef07aebf02cc7a305a80fe8e9973bf260333ad12"
},
"downloads": -1,
"filename": "drf-hcaptcha-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "bbc366abcf587feb04e280922a787d0d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8434,
"upload_time": "2023-10-08T14:07:29",
"upload_time_iso_8601": "2023-10-08T14:07:29.609797Z",
"url": "https://files.pythonhosted.org/packages/34/32/151023195c0dae83a5c747779fca528583694f9ad199cead61cf0e22f702/drf-hcaptcha-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-08 14:07:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pysashapy",
"github_project": "drf-hcaptcha",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "drf-hcaptcha"
}