my application list
This commit is contained in:
parent
58ce90ff13
commit
f01d6d3629
3 changed files with 39 additions and 2 deletions
14
apps/gooyal_oauth2/serializers.py
Executable file
14
apps/gooyal_oauth2/serializers.py
Executable file
|
|
@ -0,0 +1,14 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from .models import Application
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Application
|
||||||
|
fields = ('uuid',
|
||||||
|
'client_id',
|
||||||
|
'user',
|
||||||
|
'allowed_scope',
|
||||||
|
)
|
||||||
|
|
||||||
|
read_only_fields = fields
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
from django.urls import re_path
|
from django.urls import re_path
|
||||||
|
|
||||||
from oauth2_provider import views
|
from oauth2_provider import views
|
||||||
from .views.introspect import IntrospectTokenView, IntrospectApplicationView
|
from rest_framework import routers
|
||||||
|
|
||||||
|
from .views.introspect import IntrospectTokenView, IntrospectApplicationView
|
||||||
|
from .views import apis as api_views
|
||||||
app_name = "oauth2_provider"
|
app_name = "oauth2_provider"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -14,6 +16,8 @@ base_urlpatterns = [
|
||||||
re_path(r"^introspect_application/$", IntrospectApplicationView.as_view(), name="introspect-application"),
|
re_path(r"^introspect_application/$", IntrospectApplicationView.as_view(), name="introspect-application"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
router = routers.SimpleRouter()
|
||||||
|
router.register(r'apis/applications', api_views.ApplicationViewSet, basename='application')
|
||||||
|
|
||||||
management_urlpatterns = [
|
management_urlpatterns = [
|
||||||
# Application management views
|
# Application management views
|
||||||
|
|
@ -47,4 +51,4 @@ oidc_urlpatterns = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = base_urlpatterns + management_urlpatterns + oidc_urlpatterns
|
urlpatterns = base_urlpatterns + management_urlpatterns + oidc_urlpatterns + router.urls
|
||||||
|
|
|
||||||
19
apps/gooyal_oauth2/views/apis.py
Normal file
19
apps/gooyal_oauth2/views/apis.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from oauth2_provider.contrib.rest_framework import TokenHasScope
|
||||||
|
from rest_framework import generics
|
||||||
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||||
|
|
||||||
|
from ..models import Application
|
||||||
|
from ..rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
||||||
|
from ..serializers import ApplicationSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationViewSet(ReadOnlyModelViewSet):
|
||||||
|
serializer_class = ApplicationSerializer
|
||||||
|
lookup_field = 'uuid'
|
||||||
|
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
||||||
|
required_alternate_scopes = {
|
||||||
|
"GET": [['accounts.applications:list_or_retrieve']],
|
||||||
|
}
|
||||||
|
def get_queryset(self):
|
||||||
|
user = self.request.user
|
||||||
|
return Application.objects.filter(user=user).all()
|
||||||
Loading…
Add table
Reference in a new issue