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 "email_otp_throttling_factor", 43 "sms_otp_throttling_factor", 44 "totp_otp_throttling_factor", 45 "static_otp_throttling_factor", 46 ] 47 48 49class AuthenticatorValidateStageViewSet(UsedByMixin, ModelViewSet): 50 """AuthenticatorValidateStage Viewset""" 51 52 queryset = AuthenticatorValidateStage.objects.all() 53 serializer_class = AuthenticatorValidateStageSerializer 54 filterset_fields = ["name", "not_configured_action", "configuration_stages"] 55 ordering = ["name"] 56 search_fields = ["name"]
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 "email_otp_throttling_factor", 44 "sms_otp_throttling_factor", 45 "totp_otp_throttling_factor", 46 "static_otp_throttling_factor", 47 ]
AuthenticatorValidateStage Serializer
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
Inherited Members
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 "email_otp_throttling_factor", 44 "sms_otp_throttling_factor", 45 "totp_otp_throttling_factor", 46 "static_otp_throttling_factor", 47 ]
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', 'email_otp_throttling_factor', 'sms_otp_throttling_factor', 'totp_otp_throttling_factor', 'static_otp_throttling_factor']
class
AuthenticatorValidateStageViewSet(authentik.core.api.used_by.UsedByMixin, rest_framework.viewsets.ModelViewSet):
50class AuthenticatorValidateStageViewSet(UsedByMixin, ModelViewSet): 51 """AuthenticatorValidateStage Viewset""" 52 53 queryset = AuthenticatorValidateStage.objects.all() 54 serializer_class = AuthenticatorValidateStageSerializer 55 filterset_fields = ["name", "not_configured_action", "configuration_stages"] 56 ordering = ["name"] 57 search_fields = ["name"]
AuthenticatorValidateStage Viewset
serializer_class =
<class 'AuthenticatorValidateStageSerializer'>