簡體   English   中英

如何使用 GraphQL 自定義 Authentication 類?

[英]How to use GraphQL customized Authentication class?

使用 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 文檔中 它使用與我的項目不同的標准 Django 登錄。 我已經檢查過源LoginRequiredMixin但沒有運氣。 我在那里看不到Authentication class然后我可以覆蓋它

問題:
如何像我在DRF所做的那樣自定義 GraphQL Authentication class and Permission class

經過試驗並嘗試使用django-graphql-jwt沒有運氣。vinayan3對我的問題有答案。 因為django-cognito-jwt被認為是DRF補充。

解決方案:
只需將TokenAuthentication替換為JSONWebTokenAuthenticationdjango_cognito_jwt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM