使用 Django REST 框架(DRF(,我可以像这样简单地自定义Authentication class and Permission class
from django_cognito_jwt import JSONWebTokenAuthentication
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
class CognitoQuestionViewSet(viewsets.ModelViewSet):
authentication_classes = (JSONWebTokenAuthentication,)
permission_classes = (IsAuthenticated,)
queryset = Question.objects.all()
serializer_class = QuestionSerializer
在 GraphQL 文档中。它使用与我的项目不同的标准 Django 登录。我已经与源LoginRequiredMixin
进行了检查,但没有运气。我看不到那里Authentication class
,然后我可以覆盖它
问题:
如何像我在DRF
中所做的那样自定义 GraphQLAuthentication class and Permission class
经过试验和尝试,django-graphql-jwt
没有运气。 Vinayan3对我的问题有答案。因为django-cognito-jwt
被认为是DRF
补充。
解决方案:
只需将TokenAuthentication
替换为django_cognito_jwt
中的JSONWebTokenAuthentication