drf-recaptcha-e2e


Namedrf-recaptcha-e2e JSON
Version 1.1 PyPI version JSON
download
home_pagehttps://github.com/abhay033/drf-recaptcha_e2e.git
SummaryDjango rest framework recaptcha field serializer.
upload_time2023-06-19 10:28:15
maintainer
docs_urlNone
authorAbhay Bhati
requires_python>=3.7
licenseMIT
keywords django drf rest django-rest-framework recaptcha recaptcha v2 recaptcha v3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django REST reCAPTCHA

**Django REST reCAPTCHA v2 and v3 field serializer**

[![CI](https://github.com/llybin/drf-recaptcha/workflows/tests/badge.svg)](https://github.com/llybin/drf-recaptcha/actions)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a9b44d24cba74c75bca6472b2ee8da67)](https://www.codacy.com/app/llybin/drf-recaptcha?utm_source=github.com&utm_medium=referral&utm_content=llybin/drf-recaptcha&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/a9b44d24cba74c75bca6472b2ee8da67)](https://www.codacy.com/app/llybin/drf-recaptcha?utm_source=github.com&utm_medium=referral&utm_content=llybin/drf-recaptcha&utm_campaign=Badge_Coverage)
[![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-recaptcha)](https://pypi.org/project/drf-recaptcha/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/drf-recaptcha)](https://pypi.org/project/drf-recaptcha/)
[![PyPI - License](https://img.shields.io/pypi/l/drf-recaptcha)](https://pypi.org/project/drf-recaptcha/)

## 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.  [Sign up for reCAPTCHA](https://www.google.com/recaptcha/)
2.  Install with `pip install drf-recaptcha`
3.  Add `"drf_recaptcha"` to your `INSTALLED_APPS` settings.
4.  Set in settings `DRF_RECAPTCHA_SECRET_KEY`

```python
INSTALLED_APPS = [
   ...,
   "drf_recaptcha",
   ...,
]

...

DRF_RECAPTCHA_SECRET_KEY = "YOUR SECRET KEY"
```

## Usage

```python
from rest_framework.serializers import Serializer, ModelSerializer
from drf_recaptcha.fields import ReCaptchaV2Field, ReCaptchaV3Field
from feedback.models import Feedback


class V2Serializer(Serializer):
    recaptcha = ReCaptchaV2Field()
    ...

class GetOTPView(APIView):
    def post(self, request):
        serializer = V2Serializer(data=request.data, context={"request": request})
        serializer.is_valid(raise_exception=True)
        ...

class V3Serializer(Serializer):
    recaptcha = ReCaptchaV3Field(action="example")
    ...

class V3WithScoreSerializer(Serializer):
    recaptcha = ReCaptchaV3Field(
        action="example",
        required_score=0.6,
    )
    ...

class GetReCaptchaScore(APIView):
    def post(self, request):
        serializer = V3WithScoreSerializer(data=request.data, context={"request": request})
        serializer.is_valid()
        score = serializer.fields['recaptcha'].score
        ...

class FeedbackSerializer(ModelSerializer):
    recaptcha = ReCaptchaV2Field()

    class Meta:
        model = Feedback
        fields = ("phone", "full_name", "email", "comment", "recaptcha")

    def validate(self, attrs):
        attrs.pop("recaptcha")
        ...
        return attrs
```

## Settings

`DRF_RECAPTCHA_SECRET_KEY` - set your Google reCAPTCHA secret key. Type: str.

`DRF_RECAPTCHA_DEFAULT_V3_SCORE` - by default: `0.5`. Type: float.

`DRF_RECAPTCHA_ACTION_V3_SCORES` - by default: `{}`. Type: dict. You can define specific score for each action e.g. `{"login": 0.6, "feedback": 0.3}`

`DRF_RECAPTCHA_DOMAIN` - by default: `www.google.com`. Type: str.

`DRF_RECAPTCHA_PROXY` - by default: `{}`. Type: dict. e.g. `{'http': 'http://127.0.0.1:8000', 'https': 'https://127.0.0.1:8000'}`

`DRF_RECAPTCHA_VERIFY_REQUEST_TIMEOUT` - by default: `10`. Type: int.

## reCAPTCHA 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_RECAPTCHA_ACTION_V3_SCORES`
2.  Value in argument `required_score` of field
3.  Default value in settings `DRF_RECAPTCHA_DEFAULT_V3_SCORE`
4.  Default value `0.5`

## Testing

Set `DRF_RECAPTCHA_TESTING=True` in settings, no request to Google, no warnings, `DRF_RECAPTCHA_SECRET_KEY` is not required, set returning verification result in setting below.

`DRF_RECAPTCHA_TESTING_PASS=True|False` - all responses are pass, default `True`.

Use `from django.test import override_settings`

## Credits

[django-recaptcha](https://github.com/praekelt/django-recaptcha)

reCAPTCHA copyright 2012 Google.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/abhay033/drf-recaptcha_e2e.git",
    "name": "drf-recaptcha-e2e",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "django,drf,rest,django-rest-framework,reCAPTCHA,reCAPTCHA v2,reCAPTCHA v3",
    "author": "Abhay Bhati",
    "author_email": "abhaybhati987@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "# Django REST reCAPTCHA\n\n**Django REST reCAPTCHA v2 and v3 field serializer**\n\n[![CI](https://github.com/llybin/drf-recaptcha/workflows/tests/badge.svg)](https://github.com/llybin/drf-recaptcha/actions)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a9b44d24cba74c75bca6472b2ee8da67)](https://www.codacy.com/app/llybin/drf-recaptcha?utm_source=github.com&utm_medium=referral&utm_content=llybin/drf-recaptcha&utm_campaign=Badge_Grade)\n[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/a9b44d24cba74c75bca6472b2ee8da67)](https://www.codacy.com/app/llybin/drf-recaptcha?utm_source=github.com&utm_medium=referral&utm_content=llybin/drf-recaptcha&utm_campaign=Badge_Coverage)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![PyPI](https://img.shields.io/pypi/v/drf-recaptcha)](https://pypi.org/project/drf-recaptcha/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/drf-recaptcha)](https://pypi.org/project/drf-recaptcha/)\n[![PyPI - License](https://img.shields.io/pypi/l/drf-recaptcha)](https://pypi.org/project/drf-recaptcha/)\n\n## Requirements\n\n*   Python: 3.7, 3.8, 3.9, 3.10, 3.11\n*   Django: 3.2, 4.0, 4.1, 4.2\n*   DRF: 3.11, 3.12, 3.13, 3.14\n\n## Installation\n\n1.  [Sign up for reCAPTCHA](https://www.google.com/recaptcha/)\n2.  Install with `pip install drf-recaptcha`\n3.  Add `\"drf_recaptcha\"` to your `INSTALLED_APPS` settings.\n4.  Set in settings `DRF_RECAPTCHA_SECRET_KEY`\n\n```python\nINSTALLED_APPS = [\n   ...,\n   \"drf_recaptcha\",\n   ...,\n]\n\n...\n\nDRF_RECAPTCHA_SECRET_KEY = \"YOUR SECRET KEY\"\n```\n\n## Usage\n\n```python\nfrom rest_framework.serializers import Serializer, ModelSerializer\nfrom drf_recaptcha.fields import ReCaptchaV2Field, ReCaptchaV3Field\nfrom feedback.models import Feedback\n\n\nclass V2Serializer(Serializer):\n    recaptcha = ReCaptchaV2Field()\n    ...\n\nclass GetOTPView(APIView):\n    def post(self, request):\n        serializer = V2Serializer(data=request.data, context={\"request\": request})\n        serializer.is_valid(raise_exception=True)\n        ...\n\nclass V3Serializer(Serializer):\n    recaptcha = ReCaptchaV3Field(action=\"example\")\n    ...\n\nclass V3WithScoreSerializer(Serializer):\n    recaptcha = ReCaptchaV3Field(\n        action=\"example\",\n        required_score=0.6,\n    )\n    ...\n\nclass GetReCaptchaScore(APIView):\n    def post(self, request):\n        serializer = V3WithScoreSerializer(data=request.data, context={\"request\": request})\n        serializer.is_valid()\n        score = serializer.fields['recaptcha'].score\n        ...\n\nclass FeedbackSerializer(ModelSerializer):\n    recaptcha = ReCaptchaV2Field()\n\n    class Meta:\n        model = Feedback\n        fields = (\"phone\", \"full_name\", \"email\", \"comment\", \"recaptcha\")\n\n    def validate(self, attrs):\n        attrs.pop(\"recaptcha\")\n        ...\n        return attrs\n```\n\n## Settings\n\n`DRF_RECAPTCHA_SECRET_KEY` - set your Google reCAPTCHA secret key. Type: str.\n\n`DRF_RECAPTCHA_DEFAULT_V3_SCORE` - by default: `0.5`. Type: float.\n\n`DRF_RECAPTCHA_ACTION_V3_SCORES` - by default: `{}`. Type: dict. You can define specific score for each action e.g. `{\"login\": 0.6, \"feedback\": 0.3}`\n\n`DRF_RECAPTCHA_DOMAIN` - by default: `www.google.com`. Type: str.\n\n`DRF_RECAPTCHA_PROXY` - by default: `{}`. Type: dict. e.g. `{'http': 'http://127.0.0.1:8000', 'https': 'https://127.0.0.1:8000'}`\n\n`DRF_RECAPTCHA_VERIFY_REQUEST_TIMEOUT` - by default: `10`. Type: int.\n\n## reCAPTCHA v3\n\nValidation is passed if the score value returned by Google is greater than or equal to required score.\n\nRequired score value: `0.0 - 1.0`\n\n### Priority of score value\n\nIf not defined or zero in current item then value from next item.\n\n1.  Value for action in settings `DRF_RECAPTCHA_ACTION_V3_SCORES`\n2.  Value in argument `required_score` of field\n3.  Default value in settings `DRF_RECAPTCHA_DEFAULT_V3_SCORE`\n4.  Default value `0.5`\n\n## Testing\n\nSet `DRF_RECAPTCHA_TESTING=True` in settings, no request to Google, no warnings, `DRF_RECAPTCHA_SECRET_KEY` is not required, set returning verification result in setting below.\n\n`DRF_RECAPTCHA_TESTING_PASS=True|False` - all responses are pass, default `True`.\n\nUse `from django.test import override_settings`\n\n## Credits\n\n[django-recaptcha](https://github.com/praekelt/django-recaptcha)\n\nreCAPTCHA copyright 2012 Google.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django rest framework recaptcha field serializer.",
    "version": "1.1",
    "project_urls": {
        "Homepage": "https://github.com/abhay033/drf-recaptcha_e2e.git"
    },
    "split_keywords": [
        "django",
        "drf",
        "rest",
        "django-rest-framework",
        "recaptcha",
        "recaptcha v2",
        "recaptcha v3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3b900a3b133f2be4a4d1de9b633f57e34a305c8e72084d719df5b2c31fd23f1c",
                "md5": "86795b8613a8ca30a30e1c0fdbf99516",
                "sha256": "50042d32a3d522c90b58226da897f9012dca2741a5f5bf0e9ce939e5468cafa7"
            },
            "downloads": -1,
            "filename": "drf_recaptcha_e2e-1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "86795b8613a8ca30a30e1c0fdbf99516",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8896,
            "upload_time": "2023-06-19T10:28:15",
            "upload_time_iso_8601": "2023-06-19T10:28:15.442716Z",
            "url": "https://files.pythonhosted.org/packages/3b/90/0a3b133f2be4a4d1de9b633f57e34a305c8e72084d719df5b2c31fd23f1c/drf_recaptcha_e2e-1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-19 10:28:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "abhay033",
    "github_project": "drf-recaptcha_e2e",
    "github_not_found": true,
    "lcname": "drf-recaptcha-e2e"
}
        
Elapsed time: 1.77533s