authentik.flows.models

Flow models

  1"""Flow models"""
  2
  3from base64 import b64decode, b64encode
  4from pickle import dumps, loads  # nosec
  5from typing import TYPE_CHECKING
  6from uuid import uuid4
  7
  8from django.conf import settings
  9from django.core.validators import validate_slug
 10from django.db import models
 11from django.http import HttpRequest
 12from django.utils.translation import gettext_lazy as _
 13from model_utils.managers import InheritanceManager
 14from rest_framework.serializers import BaseSerializer
 15from structlog.stdlib import get_logger
 16
 17from authentik.admin.files.fields import FileField
 18from authentik.admin.files.manager import get_file_manager
 19from authentik.admin.files.usage import FileUsage
 20from authentik.core.models import Token
 21from authentik.core.types import UserSettingSerializer
 22from authentik.flows.challenge import FlowLayout
 23from authentik.lib.config import CONFIG
 24from authentik.lib.models import InheritanceForeignKey, InternallyManagedMixin, SerializerModel
 25from authentik.lib.utils.reflection import class_to_path
 26from authentik.policies.models import PolicyBindingModel
 27
 28if TYPE_CHECKING:
 29    from authentik.flows.planner import FlowPlan
 30    from authentik.flows.stage import StageView
 31
 32LOGGER = get_logger()
 33
 34
 35class FlowAuthenticationRequirement(models.TextChoices):
 36    """Required level of authentication and authorization to access a flow"""
 37
 38    NONE = "none"
 39    REQUIRE_AUTHENTICATED = "require_authenticated"
 40    REQUIRE_UNAUTHENTICATED = "require_unauthenticated"
 41    REQUIRE_SUPERUSER = "require_superuser"
 42    REQUIRE_REDIRECT = "require_redirect"
 43    REQUIRE_OUTPOST = "require_outpost"
 44    REQUIRE_TOKEN = "require_token"
 45
 46
 47class NotConfiguredAction(models.TextChoices):
 48    """Decides how the FlowExecutor should proceed when a stage isn't configured"""
 49
 50    SKIP = "skip"
 51    DENY = "deny"
 52    CONFIGURE = "configure"
 53
 54
 55class InvalidResponseAction(models.TextChoices):
 56    """Configure how the flow executor should handle invalid responses to challenges"""
 57
 58    RETRY = "retry"
 59    RESTART = "restart"
 60    RESTART_WITH_CONTEXT = "restart_with_context"
 61
 62
 63class FlowDeniedAction(models.TextChoices):
 64    """Configure what response is given to denied flow executions"""
 65
 66    MESSAGE_CONTINUE = "message_continue"
 67    MESSAGE = "message"
 68    CONTINUE = "continue"
 69
 70
 71class FlowDesignation(models.TextChoices):
 72    """Designation of what a Flow should be used for. At a later point, this
 73    should be replaced by a database entry."""
 74
 75    AUTHENTICATION = "authentication"
 76    AUTHORIZATION = "authorization"
 77    INVALIDATION = "invalidation"
 78    ENROLLMENT = "enrollment"
 79    UNRENOLLMENT = "unenrollment"
 80    RECOVERY = "recovery"
 81    STAGE_CONFIGURATION = "stage_configuration"
 82
 83
 84class Stage(SerializerModel):
 85    """Stage is an instance of a component used in a flow. This can verify the user,
 86    enroll the user or offer a way of recovery"""
 87
 88    stage_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
 89
 90    name = models.TextField(unique=True)
 91
 92    objects = InheritanceManager()
 93
 94    @property
 95    def view(self) -> type[StageView]:
 96        """Return StageView class that implements logic for this stage"""
 97        # This is a bit of a workaround, since we can't set class methods with setattr
 98        if hasattr(self, "__in_memory_type"):
 99            return getattr(self, "__in_memory_type")
100        raise NotImplementedError
101
102    @property
103    def component(self) -> str:
104        """Return component used to edit this object"""
105        raise NotImplementedError
106
107    def ui_user_settings(self) -> UserSettingSerializer | None:
108        """Entrypoint to integrate with User settings. Can either return None if no
109        user settings are available, or a challenge."""
110        return None
111
112    @property
113    def is_in_memory(self):
114        return hasattr(self, "__in_memory_type")
115
116    def __str__(self):
117        if self.is_in_memory:
118            return f"In-memory Stage {getattr(self, '__in_memory_type')}"
119        return f"Stage {self.name}"
120
121
122def in_memory_stage(view: type[StageView], **kwargs) -> Stage:
123    """Creates an in-memory stage instance, based on a `view` as view.
124    Any key-word arguments are set as attributes on the stage object,
125    accessible via `self.executor.current_stage`."""
126    stage = Stage()
127    # Because we can't pickle a locally generated function,
128    # we set the view as a separate property and reference a generic function
129    # that returns that member
130    setattr(stage, "__in_memory_type", view)
131    stage.name = _("Dynamic In-memory stage: {doc}").format(doc=view.__doc__)
132    stage._meta.verbose_name = class_to_path(view)
133    for key, value in kwargs.items():
134        setattr(stage, key, value)
135    return stage
136
137
138class Flow(SerializerModel, PolicyBindingModel):
139    """Flow describes how a series of Stages should be executed to authenticate/enroll/recover
140    a user. Additionally, policies can be applied, to specify which users
141    have access to this flow."""
142
143    flow_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
144
145    name = models.TextField()
146    slug = models.TextField(
147        validators=[validate_slug],
148        unique=True,
149        help_text=_("Visible in the URL."),
150    )
151
152    title = models.TextField(help_text=_("Shown as the Title in Flow pages."))
153    layout = models.TextField(default=FlowLayout.STACKED, choices=FlowLayout.choices)
154
155    designation = models.CharField(
156        max_length=100,
157        choices=FlowDesignation.choices,
158        help_text=_(
159            "Decides what this Flow is used for. For example, the Authentication flow "
160            "is redirect to when an un-authenticated user visits authentik."
161        ),
162    )
163
164    background = FileField(
165        blank=True,
166        default="",
167        help_text=_("Background shown during execution"),
168    )
169
170    compatibility_mode = models.BooleanField(
171        default=False,
172        help_text=_(
173            "Enable compatibility mode, increases compatibility with "
174            "password managers on mobile devices."
175        ),
176    )
177
178    denied_action = models.TextField(
179        choices=FlowDeniedAction.choices,
180        default=FlowDeniedAction.MESSAGE_CONTINUE,
181        help_text=_("Configure what should happen when a flow denies access to a user."),
182    )
183
184    authentication = models.TextField(
185        choices=FlowAuthenticationRequirement.choices,
186        default=FlowAuthenticationRequirement.NONE,
187        help_text=_("Required level of authentication and authorization to access a flow."),
188    )
189
190    def background_url(
191        self,
192        request: HttpRequest | None = None,
193        use_cache: bool = True,
194    ) -> str:
195        """Get the URL to the background image"""
196        if not self.background:
197            if request:
198                return request.brand.branding_default_flow_background_url(
199                    request,
200                    use_cache=use_cache,
201                )
202            return (
203                CONFIG.get("web.path", "/")[:-1] + "/static/dist/assets/images/flow_background.jpg"
204            )
205
206        return get_file_manager(FileUsage.MEDIA).file_url(
207            self.background,
208            request,
209            use_cache=use_cache,
210        )
211
212    def background_themed_urls(
213        self,
214        request: HttpRequest | None = None,
215        use_cache: bool = True,
216    ) -> dict[str, str] | None:
217        """Get themed URLs for background if it contains %(theme)s"""
218        if not self.background:
219            if request:
220                return request.brand.branding_default_flow_background_themed_urls(
221                    request,
222                    use_cache=use_cache,
223                )
224            return None
225
226        return get_file_manager(FileUsage.MEDIA).themed_urls(
227            self.background,
228            request,
229            use_cache=use_cache,
230        )
231
232    stages = models.ManyToManyField(Stage, through="FlowStageBinding", blank=True)
233
234    @property
235    def serializer(self) -> type[BaseSerializer]:
236        from authentik.flows.api.flows import FlowSerializer
237
238        return FlowSerializer
239
240    def inspector_accessible(self, request: HttpRequest) -> bool:
241        """Check if the flow inspector is accessible for this flow, permission-wise"""
242        if settings.DEBUG:
243            return True
244        if not request.user.is_authenticated or not request.user.pk:
245            return False
246        return request.user.has_perm("authentik_flows.inspect_flow", self) or request.user.has_perm(
247            "authentik_flows.inspect_flow"
248        )
249
250    def __str__(self) -> str:
251        return f"Flow {self.name} ({self.slug})"
252
253    class Meta:
254        verbose_name = _("Flow")
255        verbose_name_plural = _("Flows")
256
257        permissions = [
258            ("export_flow", _("Can export a Flow")),
259            ("inspect_flow", _("Can inspect a Flow's execution")),
260            ("view_flow_cache", _("View Flow's cache metrics")),
261            ("clear_flow_cache", _("Clear Flow's cache metrics")),
262        ]
263
264
265class FlowStageBinding(SerializerModel, PolicyBindingModel):
266    """Relationship between Flow and Stage. Order is required and unique for
267    each flow-stage Binding. Additionally, policies can be specified, which determine if
268    this Binding applies to the current user"""
269
270    fsb_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
271
272    target = models.ForeignKey("Flow", on_delete=models.CASCADE)
273    stage = InheritanceForeignKey(Stage, on_delete=models.CASCADE)
274
275    evaluate_on_plan = models.BooleanField(
276        default=False,
277        help_text=_("Evaluate policies during the Flow planning process."),
278    )
279    re_evaluate_policies = models.BooleanField(
280        default=True,
281        help_text=_("Evaluate policies when the Stage is presented to the user."),
282    )
283
284    invalid_response_action = models.TextField(
285        choices=InvalidResponseAction.choices,
286        default=InvalidResponseAction.RETRY,
287        help_text=_(
288            "Configure how the flow executor should handle an invalid response to a "
289            "challenge. RETRY returns the error message and a similar challenge to the "
290            "executor. RESTART restarts the flow from the beginning, and RESTART_WITH_CONTEXT "
291            "restarts the flow while keeping the current context."
292        ),
293    )
294
295    order = models.IntegerField()
296
297    objects = InheritanceManager()
298
299    @property
300    def serializer(self) -> type[BaseSerializer]:
301        from authentik.flows.api.bindings import FlowStageBindingSerializer
302
303        return FlowStageBindingSerializer
304
305    def __str__(self) -> str:
306        if not self.target_id and self.stage_id:
307            return f"In-memory Flow-stage binding {self.stage}"
308        return f"Flow-stage binding #{self.order} to {self.target_id}"
309
310    class Meta:
311        ordering = ["target", "order"]
312
313        verbose_name = _("Flow Stage Binding")
314        verbose_name_plural = _("Flow Stage Bindings")
315        unique_together = (("target", "stage", "order"),)
316
317
318class ConfigurableStage(models.Model):
319    """Abstract base class for a Stage that can be configured by the enduser.
320    The stage should create a default flow with the configure_stage designation during
321    migration."""
322
323    configure_flow = models.ForeignKey(
324        Flow,
325        on_delete=models.SET_NULL,
326        null=True,
327        blank=True,
328        help_text=_(
329            "Flow used by an authenticated user to configure this Stage. "
330            "If empty, user will not be able to configure this stage."
331        ),
332    )
333
334    class Meta:
335        abstract = True
336
337
338class FriendlyNamedStage(models.Model):
339    """Abstract base class for a Stage that can have a user friendly name configured."""
340
341    friendly_name = models.TextField(blank=True)
342
343    class Meta:
344        abstract = True
345
346
347class FlowToken(InternallyManagedMixin, Token):
348    """Subclass of a standard Token, stores the currently active flow plan upon creation.
349    Can be used to later resume a flow."""
350
351    flow = models.ForeignKey(Flow, on_delete=models.CASCADE)
352    _plan = models.TextField()
353    revoke_on_execution = models.BooleanField(default=True)
354
355    @staticmethod
356    def pickle(plan: FlowPlan) -> str:
357        """Pickle into string"""
358        data = dumps(plan)
359        return b64encode(data).decode()
360
361    @property
362    def plan(self) -> FlowPlan:
363        """Load Flow plan from pickled version"""
364        return loads(b64decode(self._plan.encode()))  # nosec
365
366    def __str__(self) -> str:
367        return f"Flow Token {super().__str__()}"
368
369    class Meta:
370        verbose_name = _("Flow Token")
371        verbose_name_plural = _("Flow Tokens")
LOGGER = <BoundLoggerLazyProxy(logger=None, wrapper_class=None, processors=None, context_class=None, initial_values={}, logger_factory_args=())>
class FlowAuthenticationRequirement(django.db.models.enums.TextChoices):
36class FlowAuthenticationRequirement(models.TextChoices):
37    """Required level of authentication and authorization to access a flow"""
38
39    NONE = "none"
40    REQUIRE_AUTHENTICATED = "require_authenticated"
41    REQUIRE_UNAUTHENTICATED = "require_unauthenticated"
42    REQUIRE_SUPERUSER = "require_superuser"
43    REQUIRE_REDIRECT = "require_redirect"
44    REQUIRE_OUTPOST = "require_outpost"
45    REQUIRE_TOKEN = "require_token"

Required level of authentication and authorization to access a flow

class NotConfiguredAction(django.db.models.enums.TextChoices):
48class NotConfiguredAction(models.TextChoices):
49    """Decides how the FlowExecutor should proceed when a stage isn't configured"""
50
51    SKIP = "skip"
52    DENY = "deny"
53    CONFIGURE = "configure"

Decides how the FlowExecutor should proceed when a stage isn't configured

class InvalidResponseAction(django.db.models.enums.TextChoices):
56class InvalidResponseAction(models.TextChoices):
57    """Configure how the flow executor should handle invalid responses to challenges"""
58
59    RETRY = "retry"
60    RESTART = "restart"
61    RESTART_WITH_CONTEXT = "restart_with_context"

Configure how the flow executor should handle invalid responses to challenges

class FlowDeniedAction(django.db.models.enums.TextChoices):
64class FlowDeniedAction(models.TextChoices):
65    """Configure what response is given to denied flow executions"""
66
67    MESSAGE_CONTINUE = "message_continue"
68    MESSAGE = "message"
69    CONTINUE = "continue"

Configure what response is given to denied flow executions

class FlowDesignation(django.db.models.enums.TextChoices):
72class FlowDesignation(models.TextChoices):
73    """Designation of what a Flow should be used for. At a later point, this
74    should be replaced by a database entry."""
75
76    AUTHENTICATION = "authentication"
77    AUTHORIZATION = "authorization"
78    INVALIDATION = "invalidation"
79    ENROLLMENT = "enrollment"
80    UNRENOLLMENT = "unenrollment"
81    RECOVERY = "recovery"
82    STAGE_CONFIGURATION = "stage_configuration"

Designation of what a Flow should be used for. At a later point, this should be replaced by a database entry.

STAGE_CONFIGURATION = FlowDesignation.STAGE_CONFIGURATION
class Stage(authentik.lib.models.SerializerModel):
 85class Stage(SerializerModel):
 86    """Stage is an instance of a component used in a flow. This can verify the user,
 87    enroll the user or offer a way of recovery"""
 88
 89    stage_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
 90
 91    name = models.TextField(unique=True)
 92
 93    objects = InheritanceManager()
 94
 95    @property
 96    def view(self) -> type[StageView]:
 97        """Return StageView class that implements logic for this stage"""
 98        # This is a bit of a workaround, since we can't set class methods with setattr
 99        if hasattr(self, "__in_memory_type"):
100            return getattr(self, "__in_memory_type")
101        raise NotImplementedError
102
103    @property
104    def component(self) -> str:
105        """Return component used to edit this object"""
106        raise NotImplementedError
107
108    def ui_user_settings(self) -> UserSettingSerializer | None:
109        """Entrypoint to integrate with User settings. Can either return None if no
110        user settings are available, or a challenge."""
111        return None
112
113    @property
114    def is_in_memory(self):
115        return hasattr(self, "__in_memory_type")
116
117    def __str__(self):
118        if self.is_in_memory:
119            return f"In-memory Stage {getattr(self, '__in_memory_type')}"
120        return f"Stage {self.name}"

Stage is an instance of a component used in a flow. This can verify the user, enroll the user or offer a way of recovery

def stage_uuid(unknown):

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

def name(unknown):

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

def objects(unknown):

The type of the None singleton.

view
 95    @property
 96    def view(self) -> type[StageView]:
 97        """Return StageView class that implements logic for this stage"""
 98        # This is a bit of a workaround, since we can't set class methods with setattr
 99        if hasattr(self, "__in_memory_type"):
100            return getattr(self, "__in_memory_type")
101        raise NotImplementedError

Return StageView class that implements logic for this stage

component: str
103    @property
104    def component(self) -> str:
105        """Return component used to edit this object"""
106        raise NotImplementedError

Return component used to edit this object

def ui_user_settings(self) -> authentik.core.types.UserSettingSerializer | None:
108    def ui_user_settings(self) -> UserSettingSerializer | None:
109        """Entrypoint to integrate with User settings. Can either return None if no
110        user settings are available, or a challenge."""
111        return None

Entrypoint to integrate with User settings. Can either return None if no user settings are available, or a challenge.

is_in_memory
113    @property
114    def is_in_memory(self):
115        return hasattr(self, "__in_memory_type")
flow_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example::

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

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

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

emailstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

passwordstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

endpointstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

invitationstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

promptstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatorstaticstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatorduostage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatoremailstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatorsmsstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatorwebauthnstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatorvalidatestage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticator_validate_stage_m2m_objects

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.

captchastage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

identificationstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatortotpstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

consentstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

denystage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

dummystage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

redirectstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

userdeletestage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

userloginstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

userlogoutstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

userwritestage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

accountlockdownstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

authenticatorendpointgdtcstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

mutualtlsstage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

sourcestage

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

In the example::

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

Place.restaurant is a ReverseOneToOneDescriptor instance.

class Stage.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class Stage.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

def in_memory_stage(unknown):
123def in_memory_stage(view: type[StageView], **kwargs) -> Stage:
124    """Creates an in-memory stage instance, based on a `view` as view.
125    Any key-word arguments are set as attributes on the stage object,
126    accessible via `self.executor.current_stage`."""
127    stage = Stage()
128    # Because we can't pickle a locally generated function,
129    # we set the view as a separate property and reference a generic function
130    # that returns that member
131    setattr(stage, "__in_memory_type", view)
132    stage.name = _("Dynamic In-memory stage: {doc}").format(doc=view.__doc__)
133    stage._meta.verbose_name = class_to_path(view)
134    for key, value in kwargs.items():
135        setattr(stage, key, value)
136    return stage

Creates an in-memory stage instance, based on a view as view. Any key-word arguments are set as attributes on the stage object, accessible via self.executor.current_stage.

139class Flow(SerializerModel, PolicyBindingModel):
140    """Flow describes how a series of Stages should be executed to authenticate/enroll/recover
141    a user. Additionally, policies can be applied, to specify which users
142    have access to this flow."""
143
144    flow_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
145
146    name = models.TextField()
147    slug = models.TextField(
148        validators=[validate_slug],
149        unique=True,
150        help_text=_("Visible in the URL."),
151    )
152
153    title = models.TextField(help_text=_("Shown as the Title in Flow pages."))
154    layout = models.TextField(default=FlowLayout.STACKED, choices=FlowLayout.choices)
155
156    designation = models.CharField(
157        max_length=100,
158        choices=FlowDesignation.choices,
159        help_text=_(
160            "Decides what this Flow is used for. For example, the Authentication flow "
161            "is redirect to when an un-authenticated user visits authentik."
162        ),
163    )
164
165    background = FileField(
166        blank=True,
167        default="",
168        help_text=_("Background shown during execution"),
169    )
170
171    compatibility_mode = models.BooleanField(
172        default=False,
173        help_text=_(
174            "Enable compatibility mode, increases compatibility with "
175            "password managers on mobile devices."
176        ),
177    )
178
179    denied_action = models.TextField(
180        choices=FlowDeniedAction.choices,
181        default=FlowDeniedAction.MESSAGE_CONTINUE,
182        help_text=_("Configure what should happen when a flow denies access to a user."),
183    )
184
185    authentication = models.TextField(
186        choices=FlowAuthenticationRequirement.choices,
187        default=FlowAuthenticationRequirement.NONE,
188        help_text=_("Required level of authentication and authorization to access a flow."),
189    )
190
191    def background_url(
192        self,
193        request: HttpRequest | None = None,
194        use_cache: bool = True,
195    ) -> str:
196        """Get the URL to the background image"""
197        if not self.background:
198            if request:
199                return request.brand.branding_default_flow_background_url(
200                    request,
201                    use_cache=use_cache,
202                )
203            return (
204                CONFIG.get("web.path", "/")[:-1] + "/static/dist/assets/images/flow_background.jpg"
205            )
206
207        return get_file_manager(FileUsage.MEDIA).file_url(
208            self.background,
209            request,
210            use_cache=use_cache,
211        )
212
213    def background_themed_urls(
214        self,
215        request: HttpRequest | None = None,
216        use_cache: bool = True,
217    ) -> dict[str, str] | None:
218        """Get themed URLs for background if it contains %(theme)s"""
219        if not self.background:
220            if request:
221                return request.brand.branding_default_flow_background_themed_urls(
222                    request,
223                    use_cache=use_cache,
224                )
225            return None
226
227        return get_file_manager(FileUsage.MEDIA).themed_urls(
228            self.background,
229            request,
230            use_cache=use_cache,
231        )
232
233    stages = models.ManyToManyField(Stage, through="FlowStageBinding", blank=True)
234
235    @property
236    def serializer(self) -> type[BaseSerializer]:
237        from authentik.flows.api.flows import FlowSerializer
238
239        return FlowSerializer
240
241    def inspector_accessible(self, request: HttpRequest) -> bool:
242        """Check if the flow inspector is accessible for this flow, permission-wise"""
243        if settings.DEBUG:
244            return True
245        if not request.user.is_authenticated or not request.user.pk:
246            return False
247        return request.user.has_perm("authentik_flows.inspect_flow", self) or request.user.has_perm(
248            "authentik_flows.inspect_flow"
249        )
250
251    def __str__(self) -> str:
252        return f"Flow {self.name} ({self.slug})"
253
254    class Meta:
255        verbose_name = _("Flow")
256        verbose_name_plural = _("Flows")
257
258        permissions = [
259            ("export_flow", _("Can export a Flow")),
260            ("inspect_flow", _("Can inspect a Flow's execution")),
261            ("view_flow_cache", _("View Flow's cache metrics")),
262            ("clear_flow_cache", _("Clear Flow's cache metrics")),
263        ]

Flow describes how a series of Stages should be executed to authenticate/enroll/recover a user. Additionally, policies can be applied, to specify which users have access to this flow.

def flow_uuid(unknown):

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

def name(unknown):

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

def slug(unknown):

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

def title(unknown):

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

def layout(unknown):

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

def designation(unknown):

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

def background(unknown):

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

def compatibility_mode(unknown):

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

def denied_action(unknown):

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

def authentication(unknown):

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

def background_url( self, request: django.http.request.HttpRequest | None = None, use_cache: bool = True) -> str:
191    def background_url(
192        self,
193        request: HttpRequest | None = None,
194        use_cache: bool = True,
195    ) -> str:
196        """Get the URL to the background image"""
197        if not self.background:
198            if request:
199                return request.brand.branding_default_flow_background_url(
200                    request,
201                    use_cache=use_cache,
202                )
203            return (
204                CONFIG.get("web.path", "/")[:-1] + "/static/dist/assets/images/flow_background.jpg"
205            )
206
207        return get_file_manager(FileUsage.MEDIA).file_url(
208            self.background,
209            request,
210            use_cache=use_cache,
211        )

Get the URL to the background image

def background_themed_urls( self, request: django.http.request.HttpRequest | None = None, use_cache: bool = True) -> dict[str, str] | None:
213    def background_themed_urls(
214        self,
215        request: HttpRequest | None = None,
216        use_cache: bool = True,
217    ) -> dict[str, str] | None:
218        """Get themed URLs for background if it contains %(theme)s"""
219        if not self.background:
220            if request:
221                return request.brand.branding_default_flow_background_themed_urls(
222                    request,
223                    use_cache=use_cache,
224                )
225            return None
226
227        return get_file_manager(FileUsage.MEDIA).themed_urls(
228            self.background,
229            request,
230            use_cache=use_cache,
231        )

Get themed URLs for background if it contains %(theme)s

stages

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example::

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

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

serializer: type[rest_framework.serializers.BaseSerializer]
235    @property
236    def serializer(self) -> type[BaseSerializer]:
237        from authentik.flows.api.flows import FlowSerializer
238
239        return FlowSerializer

Get serializer for this model

def inspector_accessible(self, request: django.http.request.HttpRequest) -> bool:
241    def inspector_accessible(self, request: HttpRequest) -> bool:
242        """Check if the flow inspector is accessible for this flow, permission-wise"""
243        if settings.DEBUG:
244            return True
245        if not request.user.is_authenticated or not request.user.pk:
246            return False
247        return request.user.has_perm("authentik_flows.inspect_flow", self) or request.user.has_perm(
248            "authentik_flows.inspect_flow"
249        )

Check if the flow inspector is accessible for this flow, permission-wise

def get_layout_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.

def get_designation_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.

def get_denied_action_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.

def get_authentication_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.

policybindingmodel_ptr_id
policybindingmodel_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.

provider_authentication

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.

provider_authorization

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.

provider_invalidation

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.

source_authentication

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.

source_enrollment

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.

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

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

brand_authentication

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.

brand_user_switch

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.

brand_invalidation

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.

brand_recovery

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.

brand_unenrollment

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.

brand_user_settings

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.

brand_device_code

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.

brand_lockdown

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.

brand_request

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.

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

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

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

dcr_override_authorization_flow

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.

dcr_override_invalidation_flow

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.

source_pre_authentication

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.

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

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

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

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

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

telegram_source_pre_authentication

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.

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

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

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

account_lockdown_stages

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.

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

The requested object does not exist

The query returned multiple objects when only one was expected.

266class FlowStageBinding(SerializerModel, PolicyBindingModel):
267    """Relationship between Flow and Stage. Order is required and unique for
268    each flow-stage Binding. Additionally, policies can be specified, which determine if
269    this Binding applies to the current user"""
270
271    fsb_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
272
273    target = models.ForeignKey("Flow", on_delete=models.CASCADE)
274    stage = InheritanceForeignKey(Stage, on_delete=models.CASCADE)
275
276    evaluate_on_plan = models.BooleanField(
277        default=False,
278        help_text=_("Evaluate policies during the Flow planning process."),
279    )
280    re_evaluate_policies = models.BooleanField(
281        default=True,
282        help_text=_("Evaluate policies when the Stage is presented to the user."),
283    )
284
285    invalid_response_action = models.TextField(
286        choices=InvalidResponseAction.choices,
287        default=InvalidResponseAction.RETRY,
288        help_text=_(
289            "Configure how the flow executor should handle an invalid response to a "
290            "challenge. RETRY returns the error message and a similar challenge to the "
291            "executor. RESTART restarts the flow from the beginning, and RESTART_WITH_CONTEXT "
292            "restarts the flow while keeping the current context."
293        ),
294    )
295
296    order = models.IntegerField()
297
298    objects = InheritanceManager()
299
300    @property
301    def serializer(self) -> type[BaseSerializer]:
302        from authentik.flows.api.bindings import FlowStageBindingSerializer
303
304        return FlowStageBindingSerializer
305
306    def __str__(self) -> str:
307        if not self.target_id and self.stage_id:
308            return f"In-memory Flow-stage binding {self.stage}"
309        return f"Flow-stage binding #{self.order} to {self.target_id}"
310
311    class Meta:
312        ordering = ["target", "order"]
313
314        verbose_name = _("Flow Stage Binding")
315        verbose_name_plural = _("Flow Stage Bindings")
316        unique_together = (("target", "stage", "order"),)

Relationship between Flow and Stage. Order is required and unique for each flow-stage Binding. Additionally, policies can be specified, which determine if this Binding applies to the current user

def fsb_uuid(unknown):

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

target

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

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

Child.parent is a ForwardManyToOneDescriptor instance.

stage

Forward ManyToOne Descriptor that selects subclass. Requires InheritanceAutoManager.

def evaluate_on_plan(unknown):

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

def re_evaluate_policies(unknown):

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

def invalid_response_action(unknown):

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

def order(unknown):

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

def objects(unknown):

The type of the None singleton.

serializer: type[rest_framework.serializers.BaseSerializer]
300    @property
301    def serializer(self) -> type[BaseSerializer]:
302        from authentik.flows.api.bindings import FlowStageBindingSerializer
303
304        return FlowStageBindingSerializer

Get serializer for this model

target_id
stage_id
def get_invalid_response_action_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.

policybindingmodel_ptr_id
policybindingmodel_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.

class FlowStageBinding.DoesNotExist(authentik.policies.models.PolicyBindingModel.DoesNotExist):

The requested object does not exist

class FlowStageBinding.MultipleObjectsReturned(authentik.policies.models.PolicyBindingModel.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

class ConfigurableStage(django.db.models.base.Model):
319class ConfigurableStage(models.Model):
320    """Abstract base class for a Stage that can be configured by the enduser.
321    The stage should create a default flow with the configure_stage designation during
322    migration."""
323
324    configure_flow = models.ForeignKey(
325        Flow,
326        on_delete=models.SET_NULL,
327        null=True,
328        blank=True,
329        help_text=_(
330            "Flow used by an authenticated user to configure this Stage. "
331            "If empty, user will not be able to configure this stage."
332        ),
333    )
334
335    class Meta:
336        abstract = True

Abstract base class for a Stage that can be configured by the enduser. The stage should create a default flow with the configure_stage designation during migration.

configure_flow

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

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

Child.parent is a ForwardManyToOneDescriptor instance.

configure_flow_id
class ConfigurableStage.Meta:
335    class Meta:
336        abstract = True
abstract = False
class FriendlyNamedStage(django.db.models.base.Model):
339class FriendlyNamedStage(models.Model):
340    """Abstract base class for a Stage that can have a user friendly name configured."""
341
342    friendly_name = models.TextField(blank=True)
343
344    class Meta:
345        abstract = True

Abstract base class for a Stage that can have a user friendly name configured.

def friendly_name(unknown):

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

class FriendlyNamedStage.Meta:
344    class Meta:
345        abstract = True
abstract = False
348class FlowToken(InternallyManagedMixin, Token):
349    """Subclass of a standard Token, stores the currently active flow plan upon creation.
350    Can be used to later resume a flow."""
351
352    flow = models.ForeignKey(Flow, on_delete=models.CASCADE)
353    _plan = models.TextField()
354    revoke_on_execution = models.BooleanField(default=True)
355
356    @staticmethod
357    def pickle(plan: FlowPlan) -> str:
358        """Pickle into string"""
359        data = dumps(plan)
360        return b64encode(data).decode()
361
362    @property
363    def plan(self) -> FlowPlan:
364        """Load Flow plan from pickled version"""
365        return loads(b64decode(self._plan.encode()))  # nosec
366
367    def __str__(self) -> str:
368        return f"Flow Token {super().__str__()}"
369
370    class Meta:
371        verbose_name = _("Flow Token")
372        verbose_name_plural = _("Flow Tokens")

Subclass of a standard Token, stores the currently active flow plan upon creation. Can be used to later resume a flow.

flow

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

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

Child.parent is a ForwardManyToOneDescriptor instance.

def revoke_on_execution(unknown):

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

@staticmethod
def pickle(unknown):
356    @staticmethod
357    def pickle(plan: FlowPlan) -> str:
358        """Pickle into string"""
359        data = dumps(plan)
360        return b64encode(data).decode()

Pickle into string

plan
362    @property
363    def plan(self) -> FlowPlan:
364        """Load Flow plan from pickled version"""
365        return loads(b64decode(self._plan.encode()))  # nosec

Load Flow plan from pickled version

flow_id
token_ptr_id
token_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.

class FlowToken.DoesNotExist(authentik.core.models.Token.DoesNotExist):

The requested object does not exist

class FlowToken.MultipleObjectsReturned(authentik.core.models.Token.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.