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:
20
netbox/netbox/graphql/views.py
Normal file
20
netbox/netbox/graphql/views.py
Normal 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
|
||||
Reference in New Issue
Block a user