【问题标题】:How to use GraphQL customized Authentication class?如何使用 GraphQL 自定义的 Authentication 类?
【发布时间】:2020-03-31 09:08:04
【问题描述】:

使用 Django REST Framework(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 中 docs。它使用与我的项目不同的标准 Django 登录。我检查了来源LoginRequiredMixin,但没有运气。我在那里看不到Authentication class,然后我可以覆盖它

问题:
如何自定义 GraphQL Authentication class and Permission class 就像我在 DRF 中所做的一样

【问题讨论】:

    标签: django django-rest-framework graphql jwt amazon-cognito


    【解决方案1】:

    经过试验并尝试使用django-graphql-jwt 没有运气。 vinayan3 回答了我的问题。因为django-cognito-jwt 被认为是DRF 的补码。

    解决方案:
    只需将TokenAuthentication 替换为来自django_cognito_jwtJSONWebTokenAuthentication

    【讨论】:

    • 听起来你应该可以使用django-graphql-jwts' @user_passes_test decorator 来编写自定义权限验证函数。
    • django-graphql-auth 允许使用 GraphQL 注册和管理用户帐户。它扩展了 django-graphql-jwt 以进行 JWT 身份验证。
    猜你喜欢
    • 2018-06-04
    • 2020-04-20
    • 2020-12-19
    • 2019-04-03
    • 2021-05-07
    • 2020-03-25
    • 2021-01-09
    • 2016-10-21
    • 2020-02-28
    相关资源
    最近更新 更多