authentik.providers.oauth2.api.scopes
OAuth2Provider API Views
1"""OAuth2Provider API Views""" 2 3from rest_framework.fields import CharField 4from rest_framework.serializers import ValidationError 5from rest_framework.viewsets import ModelViewSet 6 7from authentik.core.api.property_mappings import PropertyMappingFilterSet, PropertyMappingSerializer 8from authentik.core.api.used_by import UsedByMixin 9from authentik.providers.oauth2.models import ScopeMapping 10 11 12def no_space(value: str) -> str: 13 """Ensure value contains no spaces""" 14 if " " in value: 15 raise ValidationError("Value must not contain spaces.") 16 return value 17 18 19class ScopeMappingSerializer(PropertyMappingSerializer): 20 """ScopeMapping Serializer""" 21 22 scope_name = CharField(help_text="Scope name requested by the client", validators=[no_space]) 23 24 class Meta: 25 model = ScopeMapping 26 fields = PropertyMappingSerializer.Meta.fields + [ 27 "scope_name", 28 "description", 29 ] 30 31 32class ScopeMappingFilter(PropertyMappingFilterSet): 33 """Filter for ScopeMapping""" 34 35 class Meta(PropertyMappingFilterSet.Meta): 36 model = ScopeMapping 37 fields = PropertyMappingFilterSet.Meta.fields + ["scope_name"] 38 39 40class ScopeMappingViewSet(UsedByMixin, ModelViewSet): 41 """ScopeMapping Viewset""" 42 43 queryset = ScopeMapping.objects.all() 44 serializer_class = ScopeMappingSerializer 45 filterset_class = ScopeMappingFilter 46 ordering = ["scope_name", "name"] 47 search_fields = ["name", "scope_name"]
def
no_space(value: str) -> str:
13def no_space(value: str) -> str: 14 """Ensure value contains no spaces""" 15 if " " in value: 16 raise ValidationError("Value must not contain spaces.") 17 return value
Ensure value contains no spaces
20class ScopeMappingSerializer(PropertyMappingSerializer): 21 """ScopeMapping Serializer""" 22 23 scope_name = CharField(help_text="Scope name requested by the client", validators=[no_space]) 24 25 class Meta: 26 model = ScopeMapping 27 fields = PropertyMappingSerializer.Meta.fields + [ 28 "scope_name", 29 "description", 30 ]
ScopeMapping Serializer
Inherited Members
class
ScopeMappingSerializer.Meta:
25 class Meta: 26 model = ScopeMapping 27 fields = PropertyMappingSerializer.Meta.fields + [ 28 "scope_name", 29 "description", 30 ]
model =
<class 'authentik.providers.oauth2.models.ScopeMapping'>
33class ScopeMappingFilter(PropertyMappingFilterSet): 34 """Filter for ScopeMapping""" 35 36 class Meta(PropertyMappingFilterSet.Meta): 37 model = ScopeMapping 38 fields = PropertyMappingFilterSet.Meta.fields + ["scope_name"]
Filter for ScopeMapping
declared_filters =
OrderedDict({'managed': <django_filters.filters.AllValuesMultipleFilter object>, 'managed__isnull': <django_filters.filters.BooleanFilter object>})
36 class Meta(PropertyMappingFilterSet.Meta): 37 model = ScopeMapping 38 fields = PropertyMappingFilterSet.Meta.fields + ["scope_name"]
model =
<class 'authentik.providers.oauth2.models.ScopeMapping'>
class
ScopeMappingViewSet(authentik.core.api.used_by.UsedByMixin, rest_framework.viewsets.ModelViewSet):
41class ScopeMappingViewSet(UsedByMixin, ModelViewSet): 42 """ScopeMapping Viewset""" 43 44 queryset = ScopeMapping.objects.all() 45 serializer_class = ScopeMappingSerializer 46 filterset_class = ScopeMappingFilter 47 ordering = ["scope_name", "name"] 48 search_fields = ["name", "scope_name"]
ScopeMapping Viewset
serializer_class =
<class 'ScopeMappingSerializer'>
filterset_class =
<class 'ScopeMappingFilter'>