如何使用 GraphQL 自定义身份验证类?



使用 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

最新更新