1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add support for DRF token authentication

This commit is contained in:
jeremystretch
2021-06-25 09:13:08 -04:00
parent 91d39cc0c0
commit d5675a5d4a
4 changed files with 44 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
from graphene_django.views import GraphQLView as GraphQLView_
from rest_framework.decorators import authentication_classes, permission_classes, api_view
from rest_framework.permissions import IsAuthenticated
from rest_framework.settings import api_settings
class GraphQLView(GraphQLView_):
"""
Extends grpahene_django's GraphQLView to support DRF's token-based authentication.
"""
@classmethod
def as_view(cls, *args, **kwargs):
view = super(GraphQLView, cls).as_view(*args, **kwargs)
# Apply DRF permission and authentication classes
view = permission_classes((IsAuthenticated,))(view)
view = authentication_classes(api_settings.DEFAULT_AUTHENTICATION_CLASSES)(view)
view = api_view(['GET', 'POST'])(view)
return view