authentik.stages.captcha.models

authentik captcha stage

 1"""authentik captcha stage"""
 2
 3from django.db import models
 4from django.utils.translation import gettext_lazy as _
 5from django.views import View
 6from rest_framework.serializers import BaseSerializer
 7
 8from authentik.flows.models import Stage
 9
10
11class CaptchaRequestContentType(models.TextChoices):
12    """Supported request content types for CAPTCHA verification."""
13
14    FORM = "application/x-www-form-urlencoded", _("Form encoded")
15    JSON = "application/json", _("JSON")
16
17
18class CaptchaStage(Stage):
19    """Verify the user is human using Google's reCaptcha/other compatible CAPTCHA solutions."""
20
21    public_key = models.TextField(help_text=_("Public key, acquired your captcha Provider."))
22    private_key = models.TextField(help_text=_("Private key, acquired your captcha Provider."))
23
24    interactive = models.BooleanField(default=False)
25
26    score_min_threshold = models.FloatField(default=0.5)  # Default values for reCaptcha
27    score_max_threshold = models.FloatField(default=1.0)  # Default values for reCaptcha
28
29    error_on_invalid_score = models.BooleanField(
30        default=True,
31        help_text=_(
32            "When enabled and the received captcha score is outside of the given threshold, "
33            "the stage will show an error message. When not enabled, the flow will continue, "
34            "but the data from the captcha will be available in the context for policy decisions"
35        ),
36    )
37
38    js_url = models.TextField(default="https://www.recaptcha.net/recaptcha/api.js")
39    api_url = models.TextField(default="https://www.recaptcha.net/recaptcha/api/siteverify")
40    request_content_type = models.TextField(
41        choices=CaptchaRequestContentType.choices,
42        default=CaptchaRequestContentType.FORM,
43    )
44
45    @property
46    def serializer(self) -> type[BaseSerializer]:
47        from authentik.stages.captcha.api import CaptchaStageSerializer
48
49        return CaptchaStageSerializer
50
51    @property
52    def view(self) -> type[View]:
53        from authentik.stages.captcha.stage import CaptchaStageView
54
55        return CaptchaStageView
56
57    @property
58    def component(self) -> str:
59        return "ak-stage-captcha-form"
60
61    class Meta:
62        verbose_name = _("Captcha Stage")
63        verbose_name_plural = _("Captcha Stages")
class CaptchaRequestContentType(django.db.models.enums.TextChoices):
12class CaptchaRequestContentType(models.TextChoices):
13    """Supported request content types for CAPTCHA verification."""
14
15    FORM = "application/x-www-form-urlencoded", _("Form encoded")
16    JSON = "application/json", _("JSON")

Supported request content types for CAPTCHA verification.

class CaptchaStage(authentik.flows.models.Stage):
19class CaptchaStage(Stage):
20    """Verify the user is human using Google's reCaptcha/other compatible CAPTCHA solutions."""
21
22    public_key = models.TextField(help_text=_("Public key, acquired your captcha Provider."))
23    private_key = models.TextField(help_text=_("Private key, acquired your captcha Provider."))
24
25    interactive = models.BooleanField(default=False)
26
27    score_min_threshold = models.FloatField(default=0.5)  # Default values for reCaptcha
28    score_max_threshold = models.FloatField(default=1.0)  # Default values for reCaptcha
29
30    error_on_invalid_score = models.BooleanField(
31        default=True,
32        help_text=_(
33            "When enabled and the received captcha score is outside of the given threshold, "
34            "the stage will show an error message. When not enabled, the flow will continue, "
35            "but the data from the captcha will be available in the context for policy decisions"
36        ),
37    )
38
39    js_url = models.TextField(default="https://www.recaptcha.net/recaptcha/api.js")
40    api_url = models.TextField(default="https://www.recaptcha.net/recaptcha/api/siteverify")
41    request_content_type = models.TextField(
42        choices=CaptchaRequestContentType.choices,
43        default=CaptchaRequestContentType.FORM,
44    )
45
46    @property
47    def serializer(self) -> type[BaseSerializer]:
48        from authentik.stages.captcha.api import CaptchaStageSerializer
49
50        return CaptchaStageSerializer
51
52    @property
53    def view(self) -> type[View]:
54        from authentik.stages.captcha.stage import CaptchaStageView
55
56        return CaptchaStageView
57
58    @property
59    def component(self) -> str:
60        return "ak-stage-captcha-form"
61
62    class Meta:
63        verbose_name = _("Captcha Stage")
64        verbose_name_plural = _("Captcha Stages")

Verify the user is human using Google's reCaptcha/other compatible CAPTCHA solutions.

def public_key(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def private_key(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def interactive(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def score_min_threshold(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def score_max_threshold(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def error_on_invalid_score(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def js_url(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def api_url(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def request_content_type(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

serializer: type[rest_framework.serializers.BaseSerializer]
46    @property
47    def serializer(self) -> type[BaseSerializer]:
48        from authentik.stages.captcha.api import CaptchaStageSerializer
49
50        return CaptchaStageSerializer

Get serializer for this model

view: type[django.views.generic.base.View]
52    @property
53    def view(self) -> type[View]:
54        from authentik.stages.captcha.stage import CaptchaStageView
55
56        return CaptchaStageView

Return StageView class that implements logic for this stage

component: str
58    @property
59    def component(self) -> str:
60        return "ak-stage-captcha-form"

Return component used to edit this object

def get_request_content_type_display(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

stage_ptr_id
stage_ptr

Accessor to the related object on the forward side of a one-to-one relation.

In the example::

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

identificationstage_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class CaptchaStage.DoesNotExist(authentik.flows.models.Stage.DoesNotExist):

The requested object does not exist

class CaptchaStage.MultipleObjectsReturned(authentik.flows.models.Stage.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.