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

serializer: type[rest_framework.serializers.BaseSerializer]
35    @property
36    def serializer(self) -> type[BaseSerializer]:
37        from authentik.stages.captcha.api import CaptchaStageSerializer
38
39        return CaptchaStageSerializer

Get serializer for this model

view: type[django.views.generic.base.View]
41    @property
42    def view(self) -> type[View]:
43        from authentik.stages.captcha.stage import CaptchaStageView
44
45        return CaptchaStageView

Return StageView class that implements logic for this stage

component: str
47    @property
48    def component(self) -> str:
49        return "ak-stage-captcha-form"

Return component used to edit this object

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.