
* add initial Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add web stage for session end Signed-off-by: Jens Langhammer <jens@goauthentik.io> * migrate saml and tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * cleanup Signed-off-by: Jens Langhammer <jens@goauthentik.io> * group flow settings when providers have multiple flows Signed-off-by: Jens Langhammer <jens@goauthentik.io> * adjust name for default provider invalidation Signed-off-by: Jens Langhammer <jens@goauthentik.io> * re-make migrations Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add invalidation_flow to saml importer Signed-off-by: Jens Langhammer <jens@goauthentik.io> * re-do migrations again Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update web stuff to get rid of old libraries Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make unbind flow for ldap configurable Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated: fix flow inspector Signed-off-by: Jens Langhammer <jens@goauthentik.io> * handle invalidation_flow as optional, as it should be Signed-off-by: Jens Langhammer <jens@goauthentik.io> * also fix ldap outpost Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't generate URL in client Signed-off-by: Jens Langhammer <jens@goauthentik.io> * actually make it work??? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix migration breaking things...? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start fixing tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix fallback Signed-off-by: Jens Langhammer <jens@goauthentik.io> * re-migrate Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix duplicate flow setting Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add migration Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix race condition with brand Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix oauth test Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix SAML tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add to wizard, fix required Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make required, start release notes Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: Jens Langhammer <jens@goauthentik.io>
104 lines
3.6 KiB
Python
104 lines
3.6 KiB
Python
"""Provider API Views"""
|
|
|
|
from django.db.models import QuerySet
|
|
from django.db.models.query import Q
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django_filters.filters import BooleanFilter
|
|
from django_filters.filterset import FilterSet
|
|
from rest_framework import mixins
|
|
from rest_framework.fields import ReadOnlyField, SerializerMethodField
|
|
from rest_framework.viewsets import GenericViewSet
|
|
|
|
from authentik.core.api.object_types import TypesMixin
|
|
from authentik.core.api.used_by import UsedByMixin
|
|
from authentik.core.api.utils import MetaNameSerializer, ModelSerializer
|
|
from authentik.core.models import Provider
|
|
|
|
|
|
class ProviderSerializer(ModelSerializer, MetaNameSerializer):
|
|
"""Provider Serializer"""
|
|
|
|
assigned_application_slug = ReadOnlyField(source="application.slug")
|
|
assigned_application_name = ReadOnlyField(source="application.name")
|
|
assigned_backchannel_application_slug = ReadOnlyField(source="backchannel_application.slug")
|
|
assigned_backchannel_application_name = ReadOnlyField(source="backchannel_application.name")
|
|
|
|
component = SerializerMethodField()
|
|
|
|
def get_component(self, obj: Provider) -> str: # pragma: no cover
|
|
"""Get object component so that we know how to edit the object"""
|
|
if obj.__class__ == Provider:
|
|
return ""
|
|
return obj.component
|
|
|
|
class Meta:
|
|
model = Provider
|
|
fields = [
|
|
"pk",
|
|
"name",
|
|
"authentication_flow",
|
|
"authorization_flow",
|
|
"invalidation_flow",
|
|
"property_mappings",
|
|
"component",
|
|
"assigned_application_slug",
|
|
"assigned_application_name",
|
|
"assigned_backchannel_application_slug",
|
|
"assigned_backchannel_application_name",
|
|
"verbose_name",
|
|
"verbose_name_plural",
|
|
"meta_model_name",
|
|
]
|
|
extra_kwargs = {
|
|
"authorization_flow": {"required": True, "allow_null": False},
|
|
"invalidation_flow": {"required": True, "allow_null": False},
|
|
}
|
|
|
|
|
|
class ProviderFilter(FilterSet):
|
|
"""Filter for providers"""
|
|
|
|
application__isnull = BooleanFilter(method="filter_application__isnull")
|
|
backchannel = BooleanFilter(
|
|
method="filter_backchannel",
|
|
label=_(
|
|
"When not set all providers are returned. When set to true, only backchannel "
|
|
"providers are returned. When set to false, backchannel providers are excluded"
|
|
),
|
|
)
|
|
|
|
def filter_application__isnull(self, queryset: QuerySet, name, value):
|
|
"""Only return providers that are neither assigned to application,
|
|
both as provider or application provider"""
|
|
return queryset.filter(
|
|
Q(backchannel_application__isnull=value, is_backchannel=True)
|
|
| Q(application__isnull=value)
|
|
)
|
|
|
|
def filter_backchannel(self, queryset: QuerySet, name, value):
|
|
"""By default all providers are returned. When set to true, only backchannel providers are
|
|
returned. When set to false, backchannel providers are excluded"""
|
|
return queryset.filter(is_backchannel=value)
|
|
|
|
|
|
class ProviderViewSet(
|
|
TypesMixin,
|
|
mixins.RetrieveModelMixin,
|
|
mixins.DestroyModelMixin,
|
|
UsedByMixin,
|
|
mixins.ListModelMixin,
|
|
GenericViewSet,
|
|
):
|
|
"""Provider Viewset"""
|
|
|
|
queryset = Provider.objects.none()
|
|
serializer_class = ProviderSerializer
|
|
filterset_class = ProviderFilter
|
|
search_fields = [
|
|
"name",
|
|
"application__name",
|
|
]
|
|
|
|
def get_queryset(self): # pragma: no cover
|
|
return Provider.objects.select_subclasses()
|