""" Django OAuth Toolkit scopes backend for the gooyal-dynamic-scopes package. """ from django.conf import settings from django.utils import module_loading from oauth2_provider.scopes import BaseScopes from .models import Scope class Scopes(BaseScopes): """ Scopes backend that provides scopes from a Django model. """ def get_queryset(self, application=None): queryset = Scope.objects.all() if application: queryset = queryset.filter(name__in=application.allowed_scopes).order_by('resource__uuid') return queryset def get_all_scopes(self): return {scope.final_name: scope.final_description for scope in self.get_queryset().all()} def get_available_scopes(self, application=None, request=None, *args, **kwargs): scopes = [scope.final_name for scope in self.get_queryset(application).all()] return scopes def get_default_scopes(self, application=None, request=None, *args, **kwargs): return [scope.final_name for scope in self.get_queryset(application).filter(is_default=True).all()]