authentik.stages.authenticator_validate.api

AuthenticatorValidateStage API Views

 1"""AuthenticatorValidateStage API Views"""
 2
 3from rest_framework.serializers import ValidationError
 4from rest_framework.viewsets import ModelViewSet
 5
 6from authentik.core.api.used_by import UsedByMixin
 7from authentik.flows.api.stages import StageSerializer
 8from authentik.flows.models import NotConfiguredAction
 9from authentik.stages.authenticator_validate.models import AuthenticatorValidateStage
10from authentik.stages.authenticator_webauthn.api.device_types import WebAuthnDeviceTypeSerializer
11
12
13class AuthenticatorValidateStageSerializer(StageSerializer):
14    """AuthenticatorValidateStage Serializer"""
15
16    webauthn_allowed_device_types_obj = WebAuthnDeviceTypeSerializer(
17        source="webauthn_allowed_device_types", many=True, read_only=True
18    )
19
20    def validate_not_configured_action(self, value):
21        """Ensure that a configuration stage is set when not_configured_action is configure"""
22        configuration_stages = self.initial_data.get("configuration_stages", None)
23        if value == NotConfiguredAction.CONFIGURE:
24            if not configuration_stages or len(configuration_stages) < 1:
25                raise ValidationError(
26                    'When "Not configured action" is set to "Configure", '
27                    "you must set a configuration stage."
28                )
29        return value
30
31    class Meta:
32        model = AuthenticatorValidateStage
33        fields = StageSerializer.Meta.fields + [
34            "not_configured_action",
35            "device_classes",
36            "configuration_stages",
37            "last_auth_threshold",
38            "webauthn_user_verification",
39            "webauthn_hints",
40            "webauthn_allowed_device_types",
41            "webauthn_allowed_device_types_obj",
42        ]
43
44
45class AuthenticatorValidateStageViewSet(UsedByMixin, ModelViewSet):
46    """AuthenticatorValidateStage Viewset"""
47
48    queryset = AuthenticatorValidateStage.objects.all()
49    serializer_class = AuthenticatorValidateStageSerializer
50    filterset_fields = ["name", "not_configured_action", "configuration_stages"]
51    ordering = ["name"]
52    search_fields = ["name"]
class AuthenticatorValidateStageSerializer(authentik.flows.api.stages.StageSerializer):
14class AuthenticatorValidateStageSerializer(StageSerializer):
15    """AuthenticatorValidateStage Serializer"""
16
17    webauthn_allowed_device_types_obj = WebAuthnDeviceTypeSerializer(
18        source="webauthn_allowed_device_types", many=True, read_only=True
19    )
20
21    def validate_not_configured_action(self, value):
22        """Ensure that a configuration stage is set when not_configured_action is configure"""
23        configuration_stages = self.initial_data.get("configuration_stages", None)
24        if value == NotConfiguredAction.CONFIGURE:
25            if not configuration_stages or len(configuration_stages) < 1:
26                raise ValidationError(
27                    'When "Not configured action" is set to "Configure", '
28                    "you must set a configuration stage."
29                )
30        return value
31
32    class Meta:
33        model = AuthenticatorValidateStage
34        fields = StageSerializer.Meta.fields + [
35            "not_configured_action",
36            "device_classes",
37            "configuration_stages",
38            "last_auth_threshold",
39            "webauthn_user_verification",
40            "webauthn_hints",
41            "webauthn_allowed_device_types",
42            "webauthn_allowed_device_types_obj",
43        ]

AuthenticatorValidateStage Serializer

webauthn_allowed_device_types_obj
def validate_not_configured_action(self, value):
21    def validate_not_configured_action(self, value):
22        """Ensure that a configuration stage is set when not_configured_action is configure"""
23        configuration_stages = self.initial_data.get("configuration_stages", None)
24        if value == NotConfiguredAction.CONFIGURE:
25            if not configuration_stages or len(configuration_stages) < 1:
26                raise ValidationError(
27                    'When "Not configured action" is set to "Configure", '
28                    "you must set a configuration stage."
29                )
30        return value

Ensure that a configuration stage is set when not_configured_action is configure

class AuthenticatorValidateStageSerializer.Meta:
32    class Meta:
33        model = AuthenticatorValidateStage
34        fields = StageSerializer.Meta.fields + [
35            "not_configured_action",
36            "device_classes",
37            "configuration_stages",
38            "last_auth_threshold",
39            "webauthn_user_verification",
40            "webauthn_hints",
41            "webauthn_allowed_device_types",
42            "webauthn_allowed_device_types_obj",
43        ]
fields = ['pk', 'name', 'component', 'verbose_name', 'verbose_name_plural', 'meta_model_name', 'flow_set', 'not_configured_action', 'device_classes', 'configuration_stages', 'last_auth_threshold', 'webauthn_user_verification', 'webauthn_hints', 'webauthn_allowed_device_types', 'webauthn_allowed_device_types_obj']
class AuthenticatorValidateStageViewSet(authentik.core.api.used_by.UsedByMixin, rest_framework.viewsets.ModelViewSet):
46class AuthenticatorValidateStageViewSet(UsedByMixin, ModelViewSet):
47    """AuthenticatorValidateStage Viewset"""
48
49    queryset = AuthenticatorValidateStage.objects.all()
50    serializer_class = AuthenticatorValidateStageSerializer
51    filterset_fields = ["name", "not_configured_action", "configuration_stages"]
52    ordering = ["name"]
53    search_fields = ["name"]

AuthenticatorValidateStage Viewset

queryset = <InheritanceQuerySet []>
serializer_class = <class 'AuthenticatorValidateStageSerializer'>
filterset_fields = ['name', 'not_configured_action', 'configuration_stages']
ordering = ['name']
search_fields = ['name']
name = None
description = None
suffix = None
detail = None
basename = None