All Projects → llybin → Drf Recaptcha

llybin / Drf Recaptcha

Licence: mit
Django REST framework reCAPTCHA

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Drf Recaptcha

Django Rest Framework Social Oauth2
python-social-auth and oauth2 support for django-rest-framework
Stars: ✭ 941 (+1902.13%)
Mutual labels:  django, django-rest-framework
Django Rest Pandas
📊📈 Serves up Pandas dataframes via the Django REST Framework for use in client-side (i.e. d3.js) visualizations and offline analysis (e.g. Excel)
Stars: ✭ 1,030 (+2091.49%)
Mutual labels:  django, django-rest-framework
Drf Tus
A Tus (tus.io) library for Django Rest Framework
Stars: ✭ 15 (-68.09%)
Mutual labels:  django, django-rest-framework
Django Bookworm
A fun project to store my learning from each book that I read.
Stars: ✭ 23 (-51.06%)
Mutual labels:  django, django-rest-framework
Djangorestframework Mvt
Serve Mapbox Vector Tiles with Django and Postgres
Stars: ✭ 33 (-29.79%)
Mutual labels:  django, django-rest-framework
Zhihu
django + vue 仿知乎
Stars: ✭ 24 (-48.94%)
Mutual labels:  django, django-rest-framework
Ponee
A lightweight Django template ready for Heroku
Stars: ✭ 41 (-12.77%)
Mutual labels:  django, django-rest-framework
Cmdb
CMDB 配置管理系统 资产管理系统
Stars: ✭ 747 (+1489.36%)
Mutual labels:  django, django-rest-framework
Djangorestframework Book
Django REST framework 3 中文文档, API参考, 最佳实践指南
Stars: ✭ 28 (-40.43%)
Mutual labels:  django, django-rest-framework
Book Code
《Django开发从入门到实战》书籍各章节源代码
Stars: ✭ 28 (-40.43%)
Mutual labels:  django, django-rest-framework
Docker Tutorial
Docker 基本教學 - 從無到有 Docker-Beginners-Guide 教你用 Docker 建立 Django + PostgreSQL 📝
Stars: ✭ 906 (+1827.66%)
Mutual labels:  django, django-rest-framework
Algo Phantoms Backend
💻 Algo-Phantoms-Backend is an Application that provides pathways and quizzes along with a code editor to help you towards your DSA journey.📰🔥 This repository contains the REST APIs of the application.✨
Stars: ✭ 36 (-23.4%)
Mutual labels:  django, django-rest-framework
Django rest example
Django/DRF rest application example.
Stars: ✭ 17 (-63.83%)
Mutual labels:  django, django-rest-framework
Project Dashboard With Django
Agile Project Management dashboard with Django REST and Vue.js
Stars: ✭ 25 (-46.81%)
Mutual labels:  django, django-rest-framework
Django Rest Framework Gis
Geographic add-ons for Django REST Framework. Maintained by the OpenWISP Project.
Stars: ✭ 830 (+1665.96%)
Mutual labels:  django, django-rest-framework
Timed Backend
Django API for the Timed application
Stars: ✭ 15 (-68.09%)
Mutual labels:  django, django-rest-framework
Django Rest Framework Filters
Better filtering for Django REST Framework
Stars: ✭ 710 (+1410.64%)
Mutual labels:  django, django-rest-framework
Django Recaptcha
Django reCAPTCHA form field/widget integration app.
Stars: ✭ 742 (+1478.72%)
Mutual labels:  django, recaptcha
Seven23 server
Fully manual budget app to track your expenses. Opensource, with privacy by design.
Stars: ✭ 20 (-57.45%)
Mutual labels:  django, django-rest-framework
Postgraduation
University management platform dedicated for post-graduation in computer science field using django rest framework.
Stars: ✭ 35 (-25.53%)
Mutual labels:  django, django-rest-framework

Django REST reCAPTCHA

Django REST reCAPTCHA v2 and v3 field serializer

CI Codacy Badge Codacy Badge Code style: black PyPI PyPI - Downloads PyPI - License

Requirements

  • Python: 3.6, 3.7, 3.8, 3.9
  • Django: 2.2, 3.0, 3.1
  • DRF: 3.9, 3.10, 3.11, 3.12

Installation

  1. Sign up for 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
INSTALLED_APPS = [
   ...,
   "drf_recaptcha",
   ...,
]

...

DRF_RECAPTCHA_SECRET_KEY = "YOUR SECRET KEY"

Usage

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 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

reCAPTCHA copyright 2012 Google.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].